Data Structures & AlgorithmsModerateTCS NQT Digital · Infosys
Problem: For the numbers 1, 2, 3, 4, 5, how many unordered pairs (i, j) with i < j have i XOR j strictly less than 4?
- A. 5
- B. 3
- C. 6
- D. 4
Correct answer: D. 4
Check each pair's XOR against 4 directly. The pairs whose XOR is small share their high bits, which is why 1 and 2, 2 and 3 and similar pairs qualify.
More Coding Interview Problems questions
- Problem: What is the sum of the proper divisors of 220 (divisors less than 220)?
- Problem: What is the smallest positive integer n such that 1 + 2 + … + n is divisible by 10?
- Problem: Compute 7^100 mod 13.
- Problem: Using US coin denominations 1, 5, 10, 25, what is the minimum number of coins needed to make 63 (greedy works for these…
- Problem: Count the walks of length 3 on the path graph P4 (vertices 1–4, edges 1-2, 2-3, 3-4) that start and end at the same vertex. Walks…
- Problem: The array [2, 7, 4, 1, 8, 1] is examined by a sweep: for each index i, the value a[i] is compared with the minimum of the…