Skip to content

Need to add a test case to Valid Palindrome II #4831

@adamhmielke

Description

@adamhmielke

For https://neetcode.io/problems/valid-palindrome-ii

The following code is accepted

class Solution:
    def validPalindrome(self, s: str) -> bool:
        i = 0
        j = len(s) -1
        missing = False
        while(i < j):
            f = s[i]
            b = s[j]
            if f == b:
                i += 1
                j -= 1
            elif missing:
                return False
            elif f == s[j-1]:
                missing = True
                i += 1
                j -= 2
            elif s[i+1] == b:
                missing = True
                i += 2
                j -= 1
            else:
                return False
        return True

but fails the test case s="eceec" (is false but should be true)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions