title-img


Least Recently Used Cache - Amazon Top Interview Questions

Implement a least recently used cache with the following methods: LRUCache(int capacity) constructs a new instance of a LRU cache with the given capacity. get(int key) retrieves the value associated with the key key. If it does not exist, return -1. As a side effect, this key now becomes the most recently used key. set(int key, int val) updates the key key with value val. If updating this key-value pair exceeds capacity, then evicts the least recently used key-value pair. Each method shoul

View Solution →

Flight Itinerary Sequel - Amazon Top Interview Questions

You are given a list of flights that were taken, represented as origin to destination airport pairs. Given that this list was shuffled, find all the airports that were visited in the correct order. If there's more than one valid itinerary, return the lexicographically smallest ones first. Note: airports may be visited twice. Example 1 Input flights = [ ["YYZ", "SEA"], ["JFK", "YYZ"], ["SEA", "JFK"] ] Output ["JFK", "YYZ", "SEA", "JFK"] Explanation The thre

View Solution →

Movie Theatres - Amazon Top Interview Questions

Given a list of time exclusive intervals for different movie showings (possibly overlapping), find the minimum number of theatres required to be able to show all movies. Constraints 0 ≤ n ≤ 100,000 where n is the length of `intervals Example 1 Input intervals = [ [30, 75], [0, 50], [60, 150] ] Output 2 Explanation [30, 75] and [0, 50] overlap. [30, 75] and [60, 150] also overlap but later on. So the max number here is 2. Example 2 Input inter

View Solution →

Interval Union - Amazon Top Interview Questions

Given a two-dimensional integer list intervals representing unsorted inclusive intervals, return their union in sorted order. Constraints n ≤ 100,000 where n is the length of intervals Example 1 Input intervals = [ [0, 5], [4, 6] ] Output [ [0, 6] ] Example 2 Input intervals = [ [1, 2], [3, 4] ] Output [ [1, 2], [3, 4] ] Example 3 Input intervals = [ [5, 6], [1, 2] ] Output [ [1, 2], [5

View Solution →

Level Order Binary Tree to Linked List - Amazon Top Interview Questions

Given a binary tree root, convert it to a singly linked list using level order traversal. Constraints 1 ≤ n ≤ 100,000 where n is the number of nodes in root Example 1 Input root = [1, [2, null, null], [3, [4, null, null], [5, null, null]]] Output [1, 2, 3, 4, 5] Example 2 Input root = [1, [0, null, null], [2, null, null]] Output [1, 0, 2]

View Solution →