Data Structures & AlgorithmsVery hardGATE CS · TCS NQT

In [12, 4, 12, 4, 12, 4, 9] every value appears three times except one value that appears once. Which value appears once?

  1. A. 12
  2. B. 9
  3. C. 4
  4. D. 13

Correct answer: B. 9

Count set bits per position and take the count modulo 3, which isolates the single number bit by bit. Plain XOR cancels pairs but not triples, so it gives a wrong result here.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic