When equal values hide the seam.
transcript
Take the rotated list again. But now values can repeat. The right end can tie. A tie hides the seam. Let me show you the fix.
The readings are three, three, one, three. The middle ties the right end. Going left loses the one. Drop the right end by one. In 3, 3, 1, 3, the window still holds the one. Both sides stay safe.
There are now three cases. Above and below work as before. Equal drops the right end. Dropping the end is always safe. It only costs time, never correctness.
Distinct readings take seventeen steps. All equal readings take ninety-nine thousand nine hundred ninety-nine. That is the worst case. Each tie costs one step. A hundred thousand ties cost a hundred thousand steps. Interviewers ask for this on purpose.
Ties say nothing. Drop the right end by one. Say the worst case aloud. Full breakdown in the lecture.