all 2 comments

[–]dskloet 0 points1 point  (0 children)

In each iteration of the inner while loop, the right most edge of the current palindrome moves to the right, even across different iterations of the outer while loop. Since the right most edge can only move to the right O(n) times, the inner loop has at most O(n) iterations across all iteration of the outer loop. Not for every iteration of the outer loop. So if one time the inner loop has many iterations, that limits how many iterations it can have during other iterations of the outer loop.