A product analytics tool logs which feature each user action used, as feature ids in actions. A "focused" stretch is a run of neighboring actions that uses at most two different features.
Write longestFocused(actions) that returns the length of the longest focused stretch.
Input: actions = [1,2,1] Output: 3
All three actions use only features 1 and 2.
Input: actions = [0,1,2,2] Output: 3
[1, 2, 2] uses two features.
0 <= actions.length <= 1000000 <= actions[i] <= 100000Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #143 Longest Session With Two Features. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.