Data Structures & AlgorithmsModerateCAT · TCS NQT
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?
- A. 120
- B. 10
- C. 20
- D. 32
Correct answer: B. 10
Choosing the 2 blue positions fixes the row: C(5,2) = 10. Treating all balls as distinct gives 5! = 120, ordered blue positions give 20, and 2⁵ = 32 allows any colour count.
More Coding Interview Problems questions
- 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…
- Problem: Starting from the empty binary string, the value of the string "1011" read in base 2 is computed, then 3 is added. What is the…
- Problem: A list is [5, 9, 2, 7]. How many pairs (i, j) with i < j have a[i] + a[j] greater than 10?
- Problem: For the words ["sleep", "steep", "sheep", "creep"] (all of length five), how many unordered pairs differ in exactly one letter…
- Problem: The string "abcabc" is processed by replacing each character with its index in the alphabet (a=0, b=1, ..., z=25), and then the…
- Problem: A directed graph on vertices 0–4 has arcs 0→1 (2), 0→2 (6), 1→2 (3), 1→3 (9), 2→3 (1), 3→4 (2), 2→4 (8). What is the length of…