Data Structures & AlgorithmsVery hardICPC regional · Amazon SDE OA
How many entries of [7, 8, 11, 16, 15, 3] have the largest number of 1-bits in the array?
- A. 2
- B. 0
- C. 1
- D. 3
Correct answer: C. 1
Compute the 1-bit count of each element, take the maximum and count how many elements reach it. Counting the value rather than the number of matching elements is the trap.
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
- Sort all suffixes of "banana" lexicographically. What is the sum of the lengths of the longest common prefixes of each pair of adjacent…
- How many distinct substrings of length 4 does "abcabcabca" contain?
- How many proper borders (non-empty proper prefixes that are also suffixes) does "abaabaaba" have?
- Using z[0] = 0, what is the sum of the Z-function values over all indices of "aabxaayaab"?
- Starting at index 0 of [3, 2, 1, 0, 4], each value a[i] allows a jump of at most a[i] steps forward. Can the last index be reached?
- What is the maximum value of a[i] + a[j] over pairs with j - i >= 2 in [5, 1, 8, 2, 9, 3]?