Data Structures & AlgorithmsHard
What is the minimum number of positive integers (each value at most 10, repetitions allowed in the array) needed so that EVERY integer from 1 to 10 is the sum of some subset of them, each element used at most once?
- A. 3
- B. 5
- C. 10
- D. 4
Correct answer: D. 4
Binary-style reasoning shows that 1, 2, 4 cover only up to 7, so a fourth element is needed to reach 10. A brute check over multisets confirms that four values such as 1, 2, 4, 4 reach every target from 1 to 10.
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
- Given a sorted array, why is counting triplets with sum < T O(n²) rather than O(n³)?
- Floyd's cycle detection finds the slow and fast pointers meeting inside the loop. How is the START of the loop then found?
- In the greedy patching algorithm, the reachable range is [1..R] and the next sorted value x exceeds R+1. Why is R+1 the right patch?
- A monotonic deque for sliding-window maximum stores array INDICES instead of values. Why?
- When tracking a '' wildcard that may be '(', ')' or empty while scanning brackets, why is it enough to keep a range [lo, hi] of possible…
- Two different strings produced equal rolling-hash values. What does this tell you?