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?

  1. A. 10
  2. B. 6
  3. C. 3
  4. 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.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic