Data Structures & AlgorithmsModerate
How many NON-EMPTY subsets of [3, 6, 9, 12, 15, 4, 8, 11] (chosen by index, so equal values are different elements) have a sum divisible by 3?
- A. 95
- B. 96
- C. 90
- D. 64
Correct answer: A. 95
Counting subsets by index over 2^n choices, the empty subset (sum 0) is divisible by 3 but is not allowed. Including it adds one, dropping the singletons loses real answers, and a remainder-1 count answers a different question.
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 subsets of {1, 2, 3, 4, 5, 6, 7, 8} have sum exactly 15? (The empty set is excluded, and each value is used at most once.)
- How many arrays of length 4 with values from {1, 2, ..., 3} have no two adjacent elements equal?
- Each step adds 1 to one element of [2, 2, 2, 5, 5, 1]. What is the minimum total number of steps so that every element becomes distinct?…
- A sorted array [1, 5, 10] is given. You may insert new positive integers into it. What is the minimum number of insertions so that every…
- What is the smallest positive integer that CANNOT be written as the sum of some subset (each element used at most once) of the sorted…
- For the array [1, -2, 3, -1, 4, -6, 2], what is the maximum possible sum of a contiguous non-empty subarray after deleting AT MOST one of…