Data Structures & AlgorithmsModerateICPC regional · Amazon SDE OA
In the array [1, 2, 1, 3, 2, 5] exactly two values appear once and every other value appears twice. Which two values are they, as a sorted pair?
- A. 1 3
- B. 2 5
- C. 3 5
- D. 3
Correct answer: C. 3 5
XOR of all elements equals a ^ b where a and b are the two singletons. Split the set by a set bit of that XOR to separate them; a single-value XOR is not enough to identify both.
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 value of sum of popcount(i) for i from 1 to 20 (number of 1-bits in the binary form of each i, summed)?
- For the array [6, 12, 5, 8], what is the sum of (x & -x) over all elements x, where x & -x is the lowest set bit of x?
- How many contiguous subarrays of [1, 2, 4, 3, 6] have a bitwise OR equal to exactly 7?
- How many distinct non-empty substrings does the string "abacaba" have?
- In the string "ababababa", how many times does "aba" occur, counting overlapping occurrences?
- For the string "aabaaab", what is the last value of the KMP prefix-function (the length of the longest proper prefix that is also a suffix…