Data Structures & AlgorithmsHard

In 4 7 4 2 7 2 9, which value occurs most often? If several values tie, pick the one whose FIRST occurrence is earliest. Give that value.

  1. A. 2
  2. B. 9
  3. C. 4
  4. D. 5

Correct answer: C. 4

Count frequencies in a hash map and break ties by the earliest first index stored alongside. Choosing the later first occurrence, the smallest value, or the least frequent value gives different answers.

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

Exams that ask this topic