Data Structures & AlgorithmsHardLeetCode-style · Codeforces Div2 C

Koko has banana piles [3, 6, 7, 11] and H = 8 hours. Each hour she eats up to k bananas from ONE pile (if a pile has fewer, she finishes it and waits for the next hour). What is the minimum integer speed k that lets her finish within 8 hours?

  1. A. 3
  2. B. 5
  3. C. 4
  4. D. 8

Correct answer: C. 4

Binary search k: finishing pile p takes ceil(p/k) hours, so a speed is feasible when the total of ceil(p/k) is at most H. Using floor division undercounts the partial hour for each pile, which gives a speed that is too small.

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

Exams that ask this topic