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?

  1. A. 7
  2. B. 5
  3. C. 6
  4. 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

Exams that ask this topic