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.
- A. 5
- B. 6
- C. 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.
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
- How many substrings of "abacaxayaba" are palindromes of ODD length at least 3?
- Among all distinct permutations of the letters of "dbca" sorted alphabetically, what is the 1-based position of "dbca" itself?
- List all distinct permutations of the multiset of letters in "aabc" in alphabetical order. What is the 5th string in this list?
- What is the length of the longest substring of "aabbcabccbba" in which every letter occurs an EVEN number of times (0 counts as even)?
- How many unordered pairs of positions in [2, 8, 9, 18, 4, 6, 12] have a product that is a perfect square?
- For each window of 3 consecutive elements of [1, 2, 1, 3, 2, 1, 4], count the number of DISTINCT values in it. What is the sum of these…