Data Structures & AlgorithmsHardProduct placement · Amazon/Microsoft

For [7, 3, 5, 3, 7, 2, 5], definition A returns the element whose FIRST occurrence is earliest among all repeating elements; definition B returns the element whose SECOND occurrence comes first while scanning. What do A and B return?

  1. A. A: 5, B: 3
  2. B. A: 3, B: 7
  3. C. A: 7, B: 7
  4. D. A: 7, B: 3

Correct answer: D. A: 7, B: 3

A needs counts first (7 repeats and appears at index 0). B stops at the first value already in the seen-set: 3 at index 3. The two definitions often differ, so read the question's wording carefully.

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

Exams that ask this topic