11/32
Part 3 of 6 · A growing windowLearn and do

Jump the left edge, but only past a copy still inside the window

The last column of that table is a second way to shrink. Instead of a set, keep a dict last from each key to the index where you last saw it.

When key repeats, the window must start just after its earlier copy. So left can jump to last[key] + 1 in one move, instead of stepping there. In the trace above, the u1 at right 7 was last seen at index 3, so left jumps from 2 to 4.

Predict

Log u1 u2 u2 u1. At index 3, left is 2, and last says u1 was at 0. If left jumps to last[u1] + 1, what window do you get?

Pick an answer above to see the rest