Data Structures & AlgorithmsModerateTCS NQT Digital · CAT
Problem: The bitwise AND of all integers from 12 to 15 inclusive is computed. What is the result?
- A. 15
- B. 0
- C. 12
- D. 8
Correct answer: C. 12
All four share the prefix 11 and differ in the low two bits, so the AND keeps 1100 = 12. OR gives 15, XOR of 12..15 gives 0, and keeping only the top bit gives 8.
More Coding Interview Problems questions
- Problem: A row of 5 seats is filled by 3 distinct people, leaving 2 seats empty. How many arrangements are possible if the empty seats…
- Problem: The sum of the squares of the odd numbers from 1 to 19 is what value?
- Problem: A grid of 3 rows and 3 columns is filled with the numbers 1 to 9 row by row. A "line" is a complete row, column or main diagonal…
- Problem: What is the number of lattice points (x, y) with x, y ≥ 0 and x + y ≤ 5?
- Problem: The array [5, 1, 4, 2, 3] is sorted by repeatedly swapping adjacent elements that are out of order (bubble sort). How many passes…
- Problem: The Hamming weight (number of 1-bits) of each integer from 0 to 15 is summed. What is the total?