Data Structures & AlgorithmsModerateCAT · TCS NQT
Problem: A bag contains 2 red, 3 green and 4 blue balls. How many ways are there to choose 3 balls so that all three have different colours?
- A. 84
- B. 24
- C. 9
- D. 144
Correct answer: B. 24
One ball of each colour: 2 · 3 · 4 = 24. C(9,3) = 84 ignores colours, adding gives 9, and multiplying by 3! treats the picks as ordered (144).
More Coding Interview Problems questions
- Problem: The string "abcdefghij" is read two letters at a time in pairs; each pair (xy) is replaced by the pair reversed (yx). What is the…
- Problem: The sum of the numbers in the sequence 1, 1+2, 1+2+3, …, up to 1+2+…+12 is what value?
- Problem: In the array [2, 4, 6, 8, 10], count the number of subarrays whose sum is divisible by 4.
- Problem: A stack-based bracket checker reads the string "([]{()})[" and reports the number of unmatched opening brackets at the end (0 if…
- Problem: An LRU cache of capacity 2 handles requests 1, 2, 1, 3, 2, 1, 4. Each request that is not cached causes a miss and evicts the…
- Problem: Find the number of integer pairs (a, b) with 1 ≤ a ≤ b ≤ 12 such that a and b have the same remainder when divided by 4.