This question evaluates a candidate's understanding of array-processing algorithms, duplicate detection, and maintaining state to identify the longest contiguous subarray with distinct values, assessing algorithmic thinking and data structure usage.
Given an array shows of integers, return the longest contiguous subarray in which all values are distinct (no repeats within the subarray).
shows: List[int]
List[int]
(the subarray values)
If multiple subarrays have the same maximum length, return the one with the smallest starting index.
shows = [1, 2, 3, 2, 4]
→
[1, 2, 3]
shows = [5, 5, 5]
→
[5]
shows = []
→
[]
O(n)
time.
O(n)
is allowed.