Skip to content

Bug Report for longest-substring-without-duplicates (not enough test cases) #4392

@timamz

Description

@timamz

Bug Report for https://neetcode.io/problems/longest-substring-without-duplicates

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

I have submitted the solution for the problem "Longest Substring Without Repeating Characters".

class Solution:
    def lengthOfLongestSubstring(self, s: str) -> int:
        if len(s) <= 1: return len(s)

        longest_set = set(s[0])
        cur_longest = 1
        l = 0
        for r in range(1, len(s)):
            if s[r] == s[l]:
                l += 1
            else:
                if s[r] not in longest_set:
                    longest_set.add(s[r])
                    cur_longest = max(cur_longest, len(longest_set))
                else:

                    longest_set = set(s[r])
                    l = r

        return cur_longest

The submission was accepted but the solution is incorrect (checked on leetcode). For example for the input s="ohvhjdml" proposed solution yields 5 while the correct answer is 6.

Image

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