Data Structures & AlgorithmsHardTCS NQT Digital · CAT
Problem: For the set {1, 2, 3, 4, 5, 6, 7, 8}, how many 3-element subsets have a sum that is even?
- A. 28
- B. 56
- C. 4
- D. 24
Correct answer: A. 28
An even sum needs 0 or 2 odd elements: C(4,3) + C(4,2) · C(4,1) = 4 + 24 = 28. 56 counts every 3-subset, 4 counts only all-even subsets, and 24 forgets the all-even case.
More Coding Interview Problems questions
- Problem: In a list of 6 candidates, each candidate is either rejected or accepted. The number of ways to accept at least 2 and at most 4…
- Problem: A sequence is generated from 1 by repeatedly applying: x → x + (x mod 4). Starting at x = 1, what is the value after 6 steps?
- Problem: An array of length 7 holds the values 0 to 6 in some order; the position of value k is pos[k]. For the array [2, 0, 3, 6, 1, 5…
- Problem: From the string "3a7b2c" the digits are extracted and summed. What is the sum of the digits?
- Problem: The number of ways to place 3 identical red balls and 2 identical blue balls in a row of 5 positions is what value?
- Problem: The matrix [[1,2],[3,4]] is raised to the power 3 (matrix multiplication, not element-wise). What is the entry in row 0, column 0…