Data Structures & AlgorithmsVery hardGATE CS · TCS NQT
From the multiset [6, 1, 4, 2, 5, 3], choose as many elements as possible (order irrelevant) with total at most 10. What is the maximum count?
- A. 5
- B. 4
- C. 3
- D. 6
Correct answer: B. 4
Take the smallest elements first; the exchange argument shows this maximises the count for a sum bound. Here 1, 2, 3 and 4 sum 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
- How many times does "ab" occur as a substring of the string "aab" repeated three times?
- How many distinct values arise as a sum of two different elements (by position) of [3, 5, 8, 10]?
- For [1, 3, 2, 4, 6, 5, 7], how many positions already hold their correct value in the sorted array?
- How many windows of size 3 in [2, 3, 5, 1, 4, 6, 4] have a sum that is a multiple of 5?
- Sum the popcount of a[i] AND a[j] over all index pairs i < j of [7, 11, 13]. What is the total?
- What is the minimum number of characters that must be deleted from the binary string "1101001110" so that no two adjacent characters are…