Data Structures & AlgorithmsHardGATE CS · TCS NQT
How many non-empty subsets of [2, 3, 4, 5, 6] (chosen by position) have a sum that is a prime number?
- A. 12
- B. 15
- C. 10
- D. 31
Correct answer: A. 12
Enumerate all subsets with a bitmask (2⁵ = 32 of them) and test each sum for primality. Forgetting that a sum can equal a prime from a single element, or counting the empty subset, shifts the total.
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
- Five bitmasks ['0b11', '0b110', '0b1100', '0b1001', '0b101'] are available. Choose the fewest of them whose bitwise OR equals 0b1111. What…
- How many index triples i < j < k of [-4, -1, 0, 2, 3, -2, 5, 1] have a[i] + a[j] + a[k] = 0?
- How many unordered pairs of positions in [12, 21, 30, 4, 13, 9, 102] have elements with the same decimal digit sum?
- How many binary strings of length 7 contain exactly 3 zeros and NO run of three equal consecutive digits (neither 000 nor 111 appears)?
- Consider the array [1, 3, 2, 5, 4, 7, 6, 9]. You may change the value of AT MOST ONE element (to any integer). What is the length of the…
- What is the maximum value of x XOR y over all pairs of DIFFERENT positions of the list [7, 12, 5, 9, 14, 3]?