Data Structures & AlgorithmsModerateTCS NQT Digital · CAT
Problem: A bitmask represents a subset of the 4 items {A, B, C, D} by bits 0–3. How many subsets have an even number of items and do NOT contain item A (bit 0)?
- A. 5
- B. 3
- C. 6
- D. 4
Correct answer: D. 4
Enumerate the 16 masks, keep those with an even popcount and bit 0 clear. The empty set is included because it has zero items, which is even.
More Coding Interview Problems questions
- Problem: Find the number of ways to select a non-empty subset of {1, 2, 4, 8, 16} whose sum is a multiple of 5.
- Problem: In the array [3, 5, 2, 8, 6, 1], the number of elements that are greater than every element after them (right leaders) is…
- Problem: A monotone sequence is built: start with 1, and append the next number as (previous number) + (number of digits of previous…
- Problem: The numbers 1 to 20 are split into odd numbers and even numbers. What is the absolute difference between the sum of the odd…
- Problem: A string of length 5 uses the letters x, y, z. How many such strings contain each of the three letters at least once?
- Problem: The array [5, 3, 8, 6, 2, 7] is processed by the partition step of quicksort with pivot = first element (5), using the…