Data Structures & AlgorithmsHardCAT · TCS NQT
Problem: The number of ways to choose 4 people from 9 so that a specific two people are never both chosen is what value?
- A. 84
- B. 35
- C. 126
- D. 105
Correct answer: D. 105
Complement: C(9,4) − C(7,2) = 126 − 21 = 105 removes the groups containing both people. Subtracting 21 twice gives 84, excluding both people entirely gives C(7,4) = 35, and 126 ignores the restriction.
More Coding Interview Problems questions
- Problem: How many integers in [1, 10^4] are divisible by 3 and have an odd number of digits? Run the code. python print(sum(1 for x in…
- Problem: What is the number of distinct subsets sums obtainable from {2, 3, 7} (including the empty subset)? Run the code. python from…
- Problem: What is the largest prime factor of 2^20 - 1? Run the code. python n = 2 20 - 1 f = 2 last = 1 while f f <= n: while n % f == 0…
- Problem: How many numbers in [1, 500] are not divisible by 2, 3 or 5? Run the code. python print(sum(1 for x in range(1, 501) if x % 2 and…
- Problem: What is the number of inversions in the array [1, 3, 2, 5, 4, 6]? Run the code. python a = [1, 3, 2, 5, 4, 6] print(sum(1 for i…
- Problem: What is the maximum sum of a subarray with at most one element deleted from [1, -2, 3, -4, 5]? Run the code. python a = [1, -2…