Data Structures & AlgorithmsHardCodeforces Div2 C · TCS NQT

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 many pieces as you like (leftover parts are discarded). What is the largest integer length you can obtain?

  1. A. 116
  2. B. 91
  3. C. 114
  4. D. 65

Correct answer: C. 114

Binary search L with the test Σ floor(w / L) ≥ 7: at 114 the counts are 2 + 1 + 4 = 7, at 115 only 6. The average 812 / 7 = 116 ignores the wasted leftovers, testing > 7 instead of ≥ 7 gives 91, and 456 / 7 = 65 uses only the longest stick.

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

Exams that ask this topic