Longest Substring Without Repeating Characters / visualized
right always moves forward. left only moves when it has to — when the
character entering the window is already inside it. A HashSet tracks exactly what's
currently in the window, so checking "is this a duplicate?" is O(1).
Execution
idle
Press Run to begin.
0 / 0
Speed
Java · running line
in windowduplicate / shrinkingnew max
O(n) time · O(min(n, charset)) space · each character enters and leaves the window at most once — that's what makes it O(n), not O(n²).