Data Structures & AlgorithmsModerateProduct Company SDE · CP practice
Problem: A 3-person committee is chosen from 6 people. How many committees include at least one of two specific people A or B? Run the code.
Problem: A 3-person committee is chosen from 6 people. How many committees include at least one of two specific people A or B? Run the code.
from math import comb print(comb(6, 3) - comb(4, 3))What is printed?
- A. 20
- B. 12
- C. 16
- D. 4
Correct answer: C. 16
Total committees are C(6,3) = 20, and those avoiding both A and B are C(4,3) = 4, so 16 include at least one.
More Coding Interview Problems questions
- Problem: How many non-negative integer solutions (x, y, z) of x + y + z = 10 satisfy x <= 4? Run the code. python print(sum(1 for x in…
- Problem: How many pairs (x, y) with x <= y and x + y = 12 lie in 1..11? Run the code. python print(sum(1 for x in range(1, 12) for y in…
- Problem: How many inversions does the array [4, 3, 2, 1, 0] have? Run the code. python a = [4, 3, 2, 1, 0] print(sum(1 for i in…
- Problem: How many pairs (i < j) of [5, 6, 7, 9, 8] satisfy |ai - aj| = 1? Run the code. python a = [5, 6, 7, 9, 8] print(sum(1 for i in…
- Problem: How many integers in [1, 500] are multiples of 3 but not of 5? Run the code. python print(sum(1 for x in range(1, 501) if x % 3…
- Problem: How many non-negative integer pairs (x, y) satisfy 2x + 3y = 12? Run the code. python print(sum(1 for x in range(0, 7) for y in…