Find the longest stretch of visits with no repeated page
A product analytics team wants to know how long users keep exploring new pages before they start going back to pages they have already seen in that stretch. Given the ordered list of pages one user visited, find the longest contiguous stretch of visits in which no page appears twice.
Implement longestFreshStreak(visits). It returns the position of that stretch as { start, end }, where start is the index of its first visit and end is the index just after its last visit (like Array.prototype.slice).
longestFreshStreak(visits) // => { start: number, end: number }
visits.slice(start, end). It is fresh when no value appears in it twice.start.Set does (SameValueZero): NaN equals NaN, 0 equals -0, 1 and '1' differ, and objects are equal only if they are the same reference.{ start: 0, end: 0 }.visits.visits can hold 60,000 items. Checking every possible stretch is too slow.longestFreshStreak(['home', 'search', 'item', 'cart', 'search', 'item', 'checkout', 'home']);
// => { start: 3, end: 8 } ['cart', 'search', 'item', 'checkout', 'home']
longestFreshStreak(['a', 'b', 'b', 'c']);
// => { start: 0, end: 2 } 'a b' and 'b c' tie; the earlier one wins
longestFreshStreak(['feed', 'feed', 'feed']);
// => { start: 0, end: 1 }
longestFreshStreak([]);
// => { start: 0, end: 0 }