First Fit Room - Amazon Top Interview Questions
You are given a list of integers rooms and an integer target. Return the first integer in rooms that's target or larger. If there is no solution, return -1. Constraints 0 ≤ n ≤ 100,000 where n is the length of rooms Example 1 Input rooms = [15, 10, 30, 50, 25] target = 20 Output 30 Explanation 30 is the first room that's at least as large as 20. Example 2 Input rooms = [15, 10, 30, 50, 25] target = 51 Output -1 Explanation There's no room that'
View Solution →Wolves of Wall Street - Amazon Top Interview Questions
Given a list of integers prices representing the stock prices of a company in chronological order, return the maximum profit you could have made from buying and selling that stock any number of times. You must buy before you can sell it. But you are not required to buy or sell the stock. Constraints 0 ≤ n ≤ 100,000 where n is the length of prices Example 1 Input prices = [1, 5, 3, 4, 6] Output 7 Explanation We can buy at 1, sell at 5, buy at 3, and sell at 6.
View Solution →Unique Fractions - Amazon Top Interview Questions
You are given a list of lists fractions where each list contains [numerator, denominator] which represents the number numerator / denominator. Return a new list of lists such that the numbers in fractions are: In their most reduced terms. E.g. 8 / 6 becomes 4 / 3. Any duplicate fractions that represent the same value are removed. Sorted in ascending order by their value. If the number is negative, the - sign should go to the numerator (the input also follows this). Constraints n ≤
View Solution →Largest Sum After K Negations - Amazon Top Interview Questions
You are given a list of integers nums and an integer k. Consider an operation where you pick an element in nums and negate it. Given that you must make exactly k operations, return the maximum resulting sum that can be obtained. Constraints n ≤ 100,000 where n is the length of nums k < 2 ** 31 Example 1 Input nums = [1, 0, -5, -3] k = 4 Output 9 Explanation We can negate -5 and -3 once each and 0 twice to get [1, 0, 5, 3] and its sum is 9.
View Solution →Detect the Only Duplicate in a List - Amazon Top Interview Questions
You are given a list nums of length n + 1 picked from the range 1, 2, ..., n. By the pigeonhole principle, there must be a duplicate. Find and return it. There is guaranteed to be exactly one duplicate. Bonus: Can you do this in O(n) time and O(1) space? Constraints n ≤ 10,000 Example 1 Input nums = [1, 2, 3, 1] Output 1 Example 2 Input nums = [4, 2, 1, 3, 2] Output 2
View Solution →