Data Structures & AlgorithmsVery hardICPC regional · Amazon SDE OA
Five stalls are at positions 1, 2, 4, 8, 9 on a line. Three cows are placed in distinct stalls so that the minimum distance between any two cows is maximised. What is that maximum minimum distance?
- A. 4
- B. 2
- C. 3
- D. 1
Correct answer: C. 3
Binary search on the distance d and check greedily whether 3 cows fit with gaps at least d. Stalls 1, 4 and 8 give minimum gap 3; a gap of 4 is impossible, so the answer is 3.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- A conveyor must ship packages with weights 1, 2, 3, ..., 10 in the given order, in at most 5 days, and loads cannot be reordered. What is…
- What is the sum over all subarrays of [3, 1, 2, 4] of the minimum element of each subarray?
- Using a monotonic deque, the window maximum for every window of size 3 over [1, 3, -1, -3, 5, 3, 6, 7] is listed left to right. What is…
- In the array [1, 2, 1, 3, 2, 5] exactly two values appear once and every other value appears twice. Which two values are they, as a sorted…
- What is the value of sum of popcount(i) for i from 1 to 20 (number of 1-bits in the binary form of each i, summed)?
- For the array [6, 12, 5, 8], what is the sum of (x & -x) over all elements x, where x & -x is the lowest set bit of x?