Data Structures & AlgorithmsHardGATE CS · TCS NQT
How many subsets of [2, 5, 3, 7, 1] (chosen by position, empty subset included) have a total sum at most 8?
- A. 12
- B. 20
- C. 32
- D. 15
Correct answer: D. 15
Enumerate subsets or use a DP counting by sum with a prefix of capacities: the number of subsets with sum ≤ S is the sum of the DP entries up to S. Forgetting the empty subset, or using a strict inequality, gives a neighbouring count.
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 permutations of 1 to 6 have NO fixed point (that is, p[i] ≠ i for every position i)?
- How many strings of length 6 over {a, b} have NO position i with s[i] = s[i+2] (for every valid i)?
- How many arrays of length 4 with entries from {1, 2, ..., 3} are NON-INCREASING (each entry is at least the next)?
- Daily prices are [3, 2, 6, 5, 0, 3, 8, 1, 9]. You may complete at most 3 buy-then-sell transactions (one share at a time, sell before the…
- What is the maximum sum of a non-empty contiguous subarray of [4, -6, 3, -1, 7, -2, 5] that contains AT MOST one negative element?
- What is the maximum product of exactly 3 consecutive elements of [2, -3, 4, -1, 5, -6, 2]?