values of positive numbers. Choose a contiguous stretch of the array in which all numbers are distinct, so no value appears twice.
Return the largest possible sum of such a stretch.values=[3, 1, 3, 2, 5, 1] → 11
The stretch [1, 3, 2, 5] has no repeats and sums to 11, as does [3, 2, 5, 1]. No longer repeat-free stretch exists.
values=[9, 9, 9] → 9
Any stretch longer than one element repeats a value, so the answer is 9.
values=[1, 2, 10, 2, 1] → 13
Both [1, 2, 10] and [10, 2, 1] sum to 13.
values.length ≤ 10⁵values[i] ≤ 10⁴values=[3, 1, 3, 2, 5, 1]
11
Run checks the first 3 tests in your browser. Submit checks all 107 tests on the server, hidden ones included.