Data Structures & AlgorithmsVery hardICPC regional · Amazon SDE OA

How many distinct values in [3, 3, 4, 2, 4, 4, 2, 4, 4] occur strictly more than n/3 times (n = 9)?

  1. A. 2
  2. B. 0
  3. C. 1
  4. D. 3

Correct answer: C. 1

Boyer-Moore with two candidates finds all values above n/3 in one pass plus a verification pass. Only 4 occurs more than n/3 = 3 times (it occurs 5 times), so the answer is one value; the Boyer-Moore pass finds it.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic