'''
Find longest substring without repeating characters:
Input: s = "abcabcbb"
Output: 3
Explanation: The answer is "abc", with the length of 3.

Use Sliding window with a dictionary to keep track. The value will be the index and when occurance is found, it stars from ahead of the value(index)
'''


class Solution:
    def lengthOfLongestSubstring(self, s: str) -> int:
        seen = {}
        l = 0
        output = 0
        for r in range(len(s)):
            """
            If s[r] not in seen, we can keep increasing the window size by moving right pointer
            """
            if s[r] not in seen:
                output = max(output,r-l+1)

            else:
                if seen[s[r]] < l:
                    output = max(output,r-l+1)
                else:
                    l = seen[s[r]] + 1
            seen[s[r]] = r
        return output
