**Longest Substring Without Repeating Characters**

#### Description

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

#### Example

1 | Example 1: |

#### Solution

The easiest way to solove the problem is brute force, that is `O(N^2)`

complexity, this is not allowed during interviews. This problem actually is a `sliding window problem`

. We keep two pointers, one is the start `i`

, another is the end `j`

, when the current `s[j]`

already in `s[i:j]`

, we need to make the start pointer `i`

point to the next one after the existing repeated character. To acheive this, we define a `dict d`

(in python), then the value of each key is their index, so every time we check whether the current character in `d`

, if already in, we update the start pointer, and then update the current d[s[j]] = j, we need to keep the newest index of s[j].

SO based on the above solution, following is the algorithm.

##### Algorithm

*Python*

1 | def lengthOfLongestSubstring(s): |

##### Complexity

Time Complexity: O(N)

Space Complexity: O(N)

The most important part of sliding window problem is to find when is the case to update the left and right pointer.