Data Structures & AlgorithmsModerateCAT · TCS NQT
Problem: How many ordered pairs (i, j) with 1 ≤ i < j ≤ 10 satisfy i XOR j = 3?
- A. 5
- B. 3
- C. 6
- D. 4
Correct answer: D. 4
Test every pair with i < j for XOR equal to 3. Pairs must differ in exactly the bits of 3 after cancellation, so counting pairs with i + j = 3 is a different condition.
More Coding Interview Problems questions
- Problem: In how many ways can 100 be written as a sum of two perfect squares x² + y² with 0 ≤ x ≤ y (unordered, non-negative)?
- Problem: How many prime numbers are there in the range 1 to 200 (inclusive)?
- Problem: Compute σ(360), the sum of all positive divisors of 360.
- Problem: The gas-station problem: gas = [1, 2, 3, 4, 5] and cost = [3, 4, 5, 1, 2] around a circular route of 5 stations, starting with an…
- Problem: Children with greed factors g = [1, 2, 3] and cookies s = [1, 1] (each child takes at most one cookie, and a cookie of size ≥ the…
- Problem: Balloons are shot with arrows that burst every balloon whose horizontal interval contains the arrow's x position. Intervals are…