The recurrence has two cases based on whether the endpoints match. If : Both characters can extend a palindrome. Look at (the inner substring) and add .
So . If : At least one endpoint isn't part of the LPS. Take the better of excluding or excluding : . Notice the dependency: needs and . These are shorter ranges. Iterate by increasing interval length so subproblems are ready.