Data Structures & AlgorithmsHardProduct company OA · Amazon/Microsoft-style OA
Packages with weights [6, 2, 8, 4, 5, 3, 7, 1, 9] must be shipped in order using at most 3 days, each day loading a contiguous block of packages with total weight at most the capacity C. What is the smallest possible capacity C? Binary search on the answer works here.
- A. 18
- B. 17
- C. 20
- D. 15
Correct answer: B. 17
The feasibility check for a fixed capacity is monotone: a larger capacity never needs more days. Binary search over the range from the heaviest package to the total weight, with a greedy day count, finds the least feasible capacity; the average load is only a lower bound.
More Coding Interview Problems questions
- What is the minimum number of swaps of two arbitrary elements needed to sort the array [3, 1, 4, 2] into increasing order?
- Given the numbers 3, 30, 34 and 5, arrange them in some order and concatenate the decimal strings. What is the largest number that can be…
- Problem: Count (possibly overlapping) occurrences of a pattern in a text with KMP. python def kmpcount(t, p): f = [0] len(p); k = 0 for i…
- Problem: Count DISTINCT palindromic substrings by expanding around centres and collecting them in a set. python def distinctpal(s): seen =…
- Problem: Build the suffix array of a string (start indices of suffixes in sorted order) and its LCP array (Kasai's algorithm). python def…
- Problem: A Fenwick tree over a DIFFERENCE array supports 'add v to a[l..r]' and 'read a[i]' in O(log n) (1-indexed, all zeros initially)…