Data Structures & AlgorithmsModerateTCS NQT · Accenture
Problem: The 3-bit Gray code sequence is 000, 001, 011, 010, 110, 111, 101, 100 for indices 0 to 7. What is the decimal value of the element at index 5?
- A. 7
- B. 5
- C. 6
- D. 2
Correct answer: A. 7
The Gray code of i is i ⊕ (i >> 1): 5 ⊕ 2 = 7 (binary 111), matching the table. Reading the index itself gives 5, decoding instead of encoding gives 6, and 5 >> 1 alone gives 2.
More Coding Interview Problems questions
- Problem: How many subsets (including the empty set) of [1, 2, 3, 4, 5] have bitwise XOR equal to 0?
- Problem: How many integers from 1 to 100 are divisible by exactly one of 2 and 3?
- Problem: What is the last non-zero decimal digit of 10! (3628800)?
- Problem: Five people (including Alice and Bob) stand in a row. In how many arrangements do Alice and Bob stand next to each other?
- Problem: The array [3, 1, 2] undergoes one pass of bubble sort (compare each adjacent pair from left to right and swap if out of order)…
- Problem: In the array [2, 9, 4, 7, 1, 8], find the 4th smallest element using the quickselect idea (its final answer is the value that…