Data Structures & AlgorithmsVery hardProduct company OA
An extended Boyer–Moore vote keeps two candidates to find every value occurring MORE than n/3 times, then verifies them with a second pass. For [5, 1, 5, 2, 1, 5, 3, 1, 1], which values are reported?
- A. 1 only
- B. 5 and 1
- C. 5 only
- D. none
Correct answer: A. 1 only
n = 9, so a value must appear more than 3 times. 1 appears 4 times and 5 appears 3 times, so only 1 qualifies even though both survive as candidates. That is why the verification pass is required; skipping it reports 5 as well.
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
- Only the head pointer of a singly linked list of n nodes is known (no length is stored). What is the time to reach its middle node?
- An empty deque performs pushfront(1), pushfront(2), pushfront(3) and then popback(). Which value is removed?
- A sorted array holds n elements and has spare capacity. What is the worst-case time to insert a new element so that the array stays sorted?
- Counting sort on [2, 0, 2, 1, 0, 2] (values 0–2) builds count[v] and then turns it into cumulative counts, count[v] = number of elements ≤…
- Two pointers start at both ends of the sorted array [1, 3, 4, 6, 8, 11] to find pairs of DIFFERENT positions with sum 12 (move left if the…
- A hash map starts with capacity 16 and doubles its capacity whenever the number of keys EXCEEDS 0.75 × capacity. What is its capacity…