MMirrorVane
Workflows

Coding workflows · Leftmost longest palindromes

03
Built around your work

A concrete starting point

Return the leftmost longest palindromic substring of at most 512 code points. Test empty text, even centers and equal-length ties, comparing code points without Unicode normalization or grapheme segmentation.

01

Open the context

Choose the project folder and name the files or behavior involved.

02

Define the change

Describe the input, expected output and boundaries that must stay intact.

03

Inspect the work

Review the proposed edits and any commands before relying on their result.

04

Check the outcome

Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.

Leftmost longest palindromes

A concrete starting point
def longest_palindrome(text):
    if type(text) is not str or len(text) > 512:
        raise ValueError("palindrome.input")
    best = (0, 0)
    for center in range(len(text)):
        for left, right in ((center, center), (center, center+1)):
            while left >= 0 and right < len(text) and text[left] == text[right]:
                stop = right+1
                if stop-left > best[1]-best[0] or (stop-left == best[1]-best[0] and left < best[0]):
                    best = (left, stop)
                left -= 1
                right += 1
    return text[best[0]:best[1]]

The example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.

AI coding workspace

Your next change starts here.

Get the Windows app ↗