-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Open
Description
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
Labels
No labels