Complete the code to initialize the maximum length of palindrome found.
int maxLength = [1];The minimum length of a palindrome substring is 1 (a single character).
Complete the code to expand around the center and check palindrome boundaries.
while (left >= 0 && right < n && s[left] == s[right]) { left--; right++; } int length = right - left - [1];
After the while loop, left and right are one step beyond the palindrome boundaries, so subtract 1 to get the correct length.
Fix the error in the code that updates the start index of the longest palindrome found.
if (length > maxLength) { start = left + [1]; maxLength = length; }
Since left was decremented one extra time in the expansion, add 1 to get the correct start index.
Fill both blanks to correctly check for odd and even length palindromes around center i.
int len1 = expandAroundCenter(s, [1], [2]); int len2 = expandAroundCenter(s, i, i + 1);
For odd length palindrome, expand around the same center i (left and right both i).
Fill all three blanks to update start and maxLength after finding the longer palindrome length.
int maxLen = (len1 > len2) ? len1 : len2; if (maxLen > maxLength) { start = i - (maxLen - [1]) / [2]; maxLength = maxLen; end = i + maxLen / [3]; }
To find the start index, subtract half of (maxLen - 1). For end index, add half of maxLen.
