Skip to content

Bug Report for permutation-string #4956

@Enigma2612

Description

@Enigma2612

Bug Report for https://neetcode.io/problems/permutation-string

Please describe the bug below and include any steps to reproduce the bug or screenshots if possible.


In a few of the test cases, when I submit the code, it is giving me a runtime error (string index out of range), but when I use the same test case and run my code against it, the code runs, but the answer does not match.

My code (Python):

class Solution:
    def checkInclusion(self, s1: str, s2: str) -> bool:
        check = {}
        for i in s1:
            check[i] = check.get(i, 0) + 1
        
        dic = {}
        size = len(s1)

        if len(s1) > len(s2):
            return False

        for i in range(size):
            dic[s2[i]] = dic.get(s2[i], 0) + 1             #This is the line that gives error

        if dic == check:           #This one
            return True
        
        for i in range(0, len(s2) - size):
            if dic == check:                
                return True
            dic[s2[i]] -= 1
            if not dic[s2[i]]:
                del dic[s2[i]]
            dic[s2[i+size]] = dic.get(s2[i+size], 0) + 1
            if dic == check:       #This one
                return True

        return False

If either of the 2 marked 'if' conditions are omitted, this bug pops up.

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