Data Structures & AlgorithmsModerateProduct company OA · Amazon/Microsoft-style OA

What is the length of the longest run of equal consecutive values in [4, 4, 1, 2, 2, 2, 5, 1]?

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

Correct answer: D. 3

Track the current run length and reset it when the value changes; the longest run is 2, 2, 2 which has length 3. Counting distinct values gives a different quantity.

More Coding Interview Problems questions

Exams that ask this topic