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?
- A. 12
- B. 9
- C. 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.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- What is the maximum value of a[i] XOR a[j] over index pairs i < j in [3, 10, 5, 25, 2, 8]?
- How many index pairs i < j in [6, 1, 8, 7, 3, 4] have a[i] AND a[j] = 0?
- How many times does the pattern "ababa" occur in the text "ababcababa", counting overlapping occurrences?
- How many palindromic substrings (counting each occurrence by position, length 1 and up included) does "abacaba" contain?
- What is the length of the longest well-formed (balanced) contiguous substring of ")()())"?
- n = 7 people stand in a circle numbered 1 to 7. Starting from person 1, every 3rd remaining person is removed until one remains. Which…