Data Structures & AlgorithmsModerateICPC regional · Amazon SDE OA
How many non-empty subsets of [1, 2, 3, 4, 6] have a sum divisible by 3?
- A. 12
- B. 31
- C. 11
- D. 2
Correct answer: C. 11
Residues mod 3 are 1, 2, 0, 1, 0; a residue DP over the 32 subsets gives 12 with sum ≡ 0, including the empty set, so 11 non-empty ones. Forgetting to remove the empty set gives 12, 31 counts every non-empty subset, and 2 counts only the singletons 3 and 6.
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 distinct value-pairs (x, y) with x <= y occur as a[i] + a[j] = 5 for some indices i < j in [1, 1, 2, 2, 3, 3, 4, 5]?
- What is the lexicographically largest substring of length 2 in "zebraqzyx"?
- Numbers 1 to 5 are pushed in order onto a stack, and pops are interleaved so that the output is 4, 3, 5, 2, 1. How many pops are performed…
- How many pairs (i, j) with 1 <= i < j <= 12 have a product i j that is a perfect square?
- Nodes 0 to 10 form a linked structure where each node i points to node (2i + 1) mod 11. Starting at node 0, how many distinct nodes lie on…
- Tasks are (duration, deadline): (4, 2), (2, 1), (3, 2), (1, 1), (5, 3), and a single machine runs them one at a time from time 0. What is…