Data Structures & AlgorithmsHardGATE CS · Codeforces Div2 C

What is the minimum number of positive perfect cubes (1, 8, 27, ...) whose sum is exactly 31? Repeats are allowed.

  1. A. 5
  2. B. 6
  3. C. 4
  4. D. 7

Correct answer: A. 5

The DP over all cubes not exceeding the target is exact. Taking the largest cube that fits each time (greedy) fails for some targets, for example 32 = 27 + 1 + 1 + 1 + 1 + 1 (six cubes) while 8 + 8 + 8 + 8 uses four.

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

Exams that ask this topic