Longest palindromic substring
Return the longest palindromic substring, choosing the earliest start on a tie. Empty input returns an empty string.
text = 'cbbd'
left, right = 1, 2
print(text[left] == text[right])Reason about the state
Expand around both odd and even centres. Update only for a strictly longer palindrome to preserve the earliest equal-length answer. Before writing code, identify what each variable means after one iteration. Walk through the example and explain why the next transition preserves that meaning. Then check the smallest permitted input and a case with repeated values. A correct answer follows the contract for every input, including the boundary cases in the checks. Keep any input mutation within the stated rules; return a fresh result when the task asks for one.
Your task
Return the longest palindromic substring, choosing the earliest start on a tie. Empty input returns an empty string.
The explanation opens here once every check passes.