"""
003
longest substring without repeating char
medium

Given a string s, find the length of the longest
substring without repeating characters.
"""


class Solution:
    def lengthOfLongestSubstring(self, s):

        if not s:
            return 0

        l, r = 0, 1
        curr = set(s[0])
        max_len = 1
        while r < len(s):
            if s[r] not in curr:
                curr.add(s[r])
                max_len = max(max_len, r-l+1)
                r += 1
            else:
                while s[r] in curr:
                    curr.remove(s[l])
                    l += 1

        return max_len


result = Solution()
print(result.lengthOfLongestSubstring(s="abcdehgh"))

"""
003
longest substring without repeating char
medium

Given a string s, find the length of the longest
substring without repeating characters.
"""


class Solution:
    def lengthOfLongestSubstring(self, s):

        if not s:
            return 0

        l, r = 0, 1
        curr = set(s[0])
        max_len = 1
        while r < len(s):
            if s[r] not in curr:
                curr.add(s[r])
                max_len = max(max_len, r-l+1)
                r += 1
            else:
                while s[r] in curr:
                    curr.remove(s[l])
                    l += 1

        return max_len


result = Solution()
print(result.lengthOfLongestSubstring(s="abcdehgh"))

003 longest substring without repeating char medium  Given a string s, find the length of the longest substring without repeating characters.