Data Structures & AlgorithmsHardLeetCode-style · Codeforces Div2 C
For the array [19, 4, 33, 12, 7, 29], find the smallest positive integer d such that the sum of ceil(x / d) over all elements is at most 15. What is d?
- A. 10
- B. 6
- C. 3
- D. 9
Correct answer: D. 9
The function d ↦ Σ ceil(x/d) is non-increasing, so the smallest valid d can be found by binary search over 1 ... max(a). Using floor(x/d) instead of ceiling changes the sum, and it can accept a divisor that is too small.
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
- In a 3 × 5 multiplication table (entries i × j for 1 ≤ i ≤ 3, 1 ≤ j ≤ 5), with repeats counted, what is the 7-th smallest entry?
- Flowers bloom on the days [1, 10, 3, 10, 2] (one flower per position). You need m = 3 bouquets, and each bouquet needs k = 1 adjacent…
- Wood sticks have lengths [232, 124, 456] (integers). You need K = 7 pieces of EQUAL integer length, and you may cut each stick into as…
- How many unordered pairs of positions (i < j) in [9, 1, 6, 14, 3, 11, 7] have an absolute difference of at most 4?
- For the multiset [1, 6, 1, 9, 4, 12, 3], consider all unordered pairs of distinct positions and their absolute differences. What is the…
- What is the smallest non-negative integer x for which x³ + x is at least 1000?