Data Structures & AlgorithmsModerateTCS NQT Digital · CAT
Problem: Count the unordered pairs (x, y) with 1 ≤ x < y ≤ 7 for which x OR y equals 7.
- A. 24
- B. 12
- C. 3
- D. 13
Correct answer: B. 12
x | y = 7 means the pair covers bits 1, 2, 4; checking the 21 pairs finds 12 (every pair with 7, plus (3,4), (3,5), (5,6), etc.). Ordered pairs give 24, XOR = 7 gives 3, and allowing x = y adds (7,7) for 13.
More Coding Interview Problems questions
- Problem: In base 8, how many trailing zeros does 100! have?
- Problem: What is the sum of the divisors of 360 that are perfect squares?
- Problem: How many integers from 1 to 200 are both perfect squares and perfect cubes?
- Problem: Compute 7^2024 modulo 9.
- Problem: What is the multiplicative inverse of 3 modulo 11 (the value x with 0 ≤ x < 11 and 3x ≡ 1 mod 11)?
- Problem: The k = 2 closest points to the origin are chosen from the list (1,3), (−2,2), (5,8), (0,1). Compute the sum of the squared…