Approach hintTry it first, then revealHide
Restate the task as the longest window with at most two distinct values. Keep a frequency map of the window and shrink it from the left whenever a third type enters.
Restate the task as the longest window with at most two distinct values. Keep a frequency map of the window and shrink it from the left whenever a third type enters.