[Python3]: sliding window O(N) with explanation
Sliding window\nWe use a dictionary to store the character as the key, the last appear index has been seen so far as value.\nseen[charactor] = index\n\n move th
**Sliding window**\nWe use a dictionary to store the character as the key, the last appear index has been seen so far as value.\nseen[charactor] = index\n\n move the pointer when you met a repeated character in your window.\n\n\t  \n```\nindext    0    1    2    3   4   5   6   7\nstring    a    c    b    d   b   a   c   d\n          ^                  ^\n          |                  |\n\t\tleft               right\n\t\tseen = {a : 0, c : 1, b : 2, d: 3} \n\t\t# case 1: seen[b] = 2, current window  is s[0:4] , \n\t\t#        b is inside current window, seen[b] = 2 > left = 0. Move left pointer to seen[b] + 1 = 3\n\t\tseen = {a : 0, c : 1, b : 4, d: 3} \nindext    0    1    2    3   4   5   6   7\nstring    a    c    b    d   b   a   c   d\n\t\t\t\t\t\t ^   ^\n\t\t\t\t\t     |   |\n\t\t\t\t      left  right\t\t\nindext    0    1    2    3   4   5   6   7\nstring    a    c    b    d   b   a   c   d\n\t\t\t\t\t     ^       ^\n\t\t\t\t\t     |       |\n\t\t\t\t       left    right\t\t\n\t\t# case 2: seen[a] = 0,which means a not in current window s[3:5] , since seen[a] = 0 < left = 3 \n\t\t# we can keep moving right pointer.\n```\n\n```\nclass Solution:\n    def lengthOfLongestSubstring(self, s: str) -> int:\n        seen = {}\n        l = 0\n        output = 0\n        for r in range(len(s)):\n            """\n            If s[r] not in seen, we can keep increasing the window size by moving right pointer\n            """\n            if s[r] not in seen:\n                output = max(output,r-l+1)\n            """\n            There are two cases if s[r] in seen:\n            case1: s[r] is inside the current window, we need to change the window by moving left pointer to seen[s[r]] + 1.\n            case2: s[r] is not inside the current window, we can keep increase the window\n            """\n            else:\n                if seen[s[r]] < l:\n                    output = max(output,r-l+1)\n                else:\n                    l = seen[s[r]] + 1\n            seen[s[r]] = r\n        return output\n```\n* Time complexity :O(n). \n\tn is the length of the input string.\n\tIt will iterate n times to get the result.\n\n* Space complexity: O(m)\n\tm is the number of unique characters of the input. \n\tWe need a dictionary to store unique characters.\n\n
['Python', 'Python3']