Widest Spread Value
The spread of a value is the distance between its first and its last position in nums; a value that appears only once has spread 0.
Return the value with the largest spread. If several values tie for the largest spread, return the smallest of those values. nums is never empty.
Example 1
nums [3,1,3,2,2,9]
returns 3
3 sits at positions 0 and 2 (spread 2), 2 at positions 3 and 4 (spread 1), 1 and 9 once each (spread 0).
Example 2
nums [1,2,1,2]
returns 1
1 and 2 both have spread 2; the smaller value is returned.
Constraints
1 <= len(nums) <= 100-1000 <= nums[i] <= 1000
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Hash maps problems
- Bulls and CowsMedium
- Contiguous ArrayMedium
- Group AnagramsMedium
- Longest Consecutive SequenceMedium
- Longest Zero-Sum StretchMedium
- Rows That Match ColumnsMedium
- Shift FamiliesMedium
- Stretches With K Odd ValuesMedium