AdvancedMultiple choice
Finding the unpaired ids · Part 3 of 3
An array holds integer order ids. Unless a part says otherwise, every id appears exactly twice except the ones you are asked to find, and you may use only extra memory.
Now every id appears three times except one, which appears once. Which method finds it in time and memory?
- AXOR everything, as before
- BFor each of the 64 bit positions, count the ids with that bit set, modulo 3
- CSort the array in place with heapsort, then scan for the value that is not repeated three times
- DCount occurrences in a hash map
The worked solution is in Premium
The answer, the full working and the one idea to take away – for this and all 1,322 questions in the bank. Answer it in practice and your working is marked, with a known mistake named when you make one.
Learn the method
More data structures and algorithms questions
- How many set bits does the integer 90 have?Foundation
- For a positive integer x, which test is true exactly when x is a power of two?Foundation
- How many iterations does the loop while (x) { x &= x - 1; n++; } make on x = 255?Applied
- What is 1oplus2oplus3oplus⋯oplus10, where oplus is bitwise XOR?Applied
- Computing x¹³ by binary exponentiation (repeated squaring), how many…Applied
- A root-finding guarantee, part 1 of 3Foundation