Data Structures & AlgorithmsHardGATE CS · Codeforces Div2 C
How many NON-EMPTY subsets of [4, 7, 2, 9, 5, 3, 8, 6] have a sum divisible by 3? Subsets are chosen by position.
- A. 88
- B. 87
- C. 85
- D. 1
Correct answer: B. 87
Track the count of subsets for each remainder mod 3: each new number either joins a subset (shifting its remainder) or not. Remember to remove the empty subset, which also has remainder 0.
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
- Items as (weight, value) are [(3, 5), (4, 6), (5, 9), (7, 13), (2, 8)]. Each item can be used at most once. What is the maximum value of a…
- From the numbers [17, 22, 9, 35, 41, 13, 28], choose a subset (each number used at most once) whose sum is as large as possible without…
- Four workers (rows) and four tasks (columns) have cost matrix [[9, 2, 7, 8], [6, 4, 3, 7], [5, 8, 1, 8], [7, 6, 9, 4]], where cost[i][j]…
- Four cities have symmetric travel costs D = [[0, 27, 24, 21], [27, 0, 30, 17], [24, 30, 0, 1], [21, 17, 1, 0]]. Starting at city 0, you…
- A directed graph on vertices 0 to 3 has adjacency matrix [[0, 1, 1, 0], [0, 0, 1, 1], [0, 0, 0, 1], [1, 0, 0, 0]] (adj[i][j] = 1 means an…
- For the list [3, 5, 6, 9, 10], how many subsets (including the empty subset) have a bitwise XOR of exactly 0?