Data Structures & AlgorithmsHardGATE CS · TCS NQT
From [4, 9, 2, 7, 5, 1] you may pick any elements (each at most once). What is the minimum number of picks so that the picked sum is at least 20?
- A. 4
- B. 3
- C. 2
- D. 5
Correct answer: B. 3
Picking the largest values first is optimal: 9 + 7 + 5 = 21 reaches 20 with three picks, and two picks cannot reach 20.
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 index triples i < j < k in [-2, -1, 0, 1, 2, 3] have a sum of exactly 0?
- How many contiguous subarrays of [1, 2, 3, 4] have a sum that is a perfect square?
- A string "cdeab" is rotated left by some number of steps k (0 <= k < 5) to become "abcde". What is the smallest such k?
- What is the sum of the maximum over all contiguous subarrays of [3, 1, 2, 4]?
- How many contiguous subarrays of [2, 1, 3, 4, 2] have a sum in the inclusive range [5, 7]?
- What is the number of 1-bits in the bitwise OR of 6, 10 and 12?