04 Try it yourself Interactive

Inward, then outward

Two pointer walks over the same input, in opposite directions. Two pointers starts at both ends and converges: the amber band is the live window, a dashed cell is a character being stepped over, green is a matched pair, red is a mismatch. Expand centre starts from one centre and grows outward, trying every one of the 2n − 1 centres — 13 of them for the seven letters of the default example — with a green underline on the longest span found so far. It works on the stripped, lowercased string, so the cells change when you switch tabs. Nothing moves on its own — press Next, or use the arrow keys.

Valid palindrome
left and right converge · punctuation skipped
Up to 18 characters. Letters, digits, spaces and simple punctuation.
Press Next to begin. Each press moves one step.


      
Left
Right
Matches0
Mismatch0
step 0 / 0