Data Structures & AlgorithmsHardCodeforces Div2 C · TCS NQT
Parcels with weights [4, 9, 2, 7, 5, 8, 3, 6] must be shipped in this order, and a ship carries a contiguous block each day. What is the smallest daily capacity that lets all parcels ship within 3 days?
- A. 13
- B. 14
- C. 9
- D. 17
Correct answer: D. 17
Binary search the capacity: each day ships a maximal prefix of the remaining parcels, and the capacity is feasible when the day count is at most D. The average load (sum/D) is a lower bound, not the answer, because parcels are indivisible and must keep their order.
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
- What is the largest integer k such that 1 + 2 + ... + k is at most 2023?
- A train makes three legs of lengths 1, 3 and 2 km. Each leg except the last must be finished in whole hours (a partial hour is rounded…
- How many indices i in [1, 7, 3, 6, 5, 6] have the sum of elements strictly left of i equal to the sum of elements strictly right of i?
- How many contiguous subarrays of [1, -1, 2, -2, 3, -3, 1] sum to exactly 1?
- How many contiguous subarrays of [2, 5, 1, 4, 3] have their maximum equal to the first or the last element of the subarray?
- How many disjoint intervals remain after merging all overlapping closed intervals in [(1,3),(2,6),(8,10),(15,18),(17,20),(6,7)]?…