Find longest run of identical consecutive shows
Company: Netflix
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Quick Answer: This question evaluates array-manipulation skills and the ability to identify contiguous runs of equal values, emphasizing algorithmic efficiency and edge-case handling within the Coding & Algorithms domain. It is commonly asked to assess practical application of linear-time, constant-space processing and attention to implementation details rather than purely theoretical concepts.
Constraints
- 0 <= len(shows) <= 100000
- -1000000000 <= shows[i] <= 1000000000
- Aim for O(n) time and O(1) extra space
Examples
Input: ([7, 7, 2, 2, 2, 7],)
Expected Output: 3
Explanation: The longest contiguous block of equal values is `[2, 2, 2]`, which has length 3.
Input: ([],)
Expected Output: 0
Explanation: An empty list has no runs, so the answer is 0.
Input: ([5],)
Expected Output: 1
Explanation: A single element forms a run of length 1.
Input: ([1, 1, 1, 1],)
Expected Output: 4
Explanation: All elements are the same, so the entire array is one run of length 4.
Input: ([1, 2, 3, 4],)
Expected Output: 1
Explanation: No two consecutive elements are equal, so the longest run length is 1.
Input: ([3, 2, 2, 3, 3, 3, 2],)
Expected Output: 3
Explanation: The longest run is `[3, 3, 3]`, which has length 3.
Input: ([-1, -1, -1, 2, 2, -1],)
Expected Output: 3
Explanation: The longest run is `[-1, -1, -1]`, which has length 3.
Hints
- Compare each element with the previous one to see whether the current run continues or resets.
- Keep two counters: one for the current run length and one for the maximum run length seen so far.