Data Structures & AlgorithmsHardGATE CS · TCS NQT
How many non-empty subsets of [3, 1, 4, 2, 5] (chosen by position) have a sum between 4 and 7 inclusive?
- A. 14
- B. 11
- C. 9
- D. 8
Correct answer: B. 11
Subset-sum counting: enumerate subsets or use a DP over sums and add the counts for every target in the range. The bounds are inclusive, so off-by-one at R or L changes the answer.
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
- Choose a subsequence of length exactly 3 from [5, 1, 4, 2, 6, 3, 7, 2] (keeping order) whose elements are non-decreasing. What is the…
- How many DIFFERENT palindromic strings of length 3 occur as subsequences of "abcbaab" (each string counted once, however many index…
- Deleting exactly one character from "110100" gives a new binary string each time. How many DISTINCT strings result?
- How many DISTINCT palindromic strings (of any length ≥ 1) occur as subsequences of "abab"?
- Count the index paths from position 0 to position 6 in the array [1, 3, 2, 4, 6, 5, 7] where each move goes from index i to a LATER index…
- A binary partition of 20 is a way to write 20 as a sum of powers of two (1, 2, 4, 8, ...), where order does not matter and repeats are…