I received the OA on November 9 and took it on November 13.
Three easy-type questions.
Given an int[] A, each operation picks any two values a and b from A, removes them, and inserts a + b into A. The cost of that operation is a + b. Find the minimum total cost to reduce A to size 1. Put all the values in a min-heap. While its size is greater than 1, poll two values a and b, add the cost to the total, and put a + b back into the min-heap. Return the total at the end.
Given users[], times[], k, and t, request i comes from users[i] at timestamp times[i]. A user's allowed requests cannot exceed k within a t-second period. Output an int[] results: results[i] is 1 if request i is allowed and 0 otherwise. The problem says times is sorted. A Map<user, Queue> handles it. Before writing the result, remove expired timestamps from the corresponding user's queue.
Given an int[] prices, the cost at prices[0] is prices[0]. From prices[i] onward, the cost is prices[i] minus the minimum among the earlier prices, from index 0 through i - 1. Find the total cost from i = 0 through n - 1. Keep a prevMinCost and a total, and iterate through prices.
Discussion
Loading comments…