> For the complete documentation index, see [llms.txt](https://coding-9.gitbook.io/untitled/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://coding-9.gitbook.io/untitled/sliding-window/medium/3.-longest-substring-without-repeating-characters.md).

# 3. Longest Substring Without Repeating Characters

## Problem Statement

<br>

Given a string `s`, find the length of the **longest**&#x20;

**substring** without repeating characters.

&#x20;

**Example 1:**

<pre><code><strong>Input: s = "abcabcbb"
</strong><strong>Output: 3
</strong><strong>Explanation: The answer is "abc", with the length of 3.
</strong></code></pre>

**Example 2:**

<pre><code><strong>Input: s = "bbbbb"
</strong><strong>Output: 1
</strong><strong>Explanation: The answer is "b", with the length of 1.
</strong></code></pre>

**Example 3:**

<pre><code><strong>Input: s = "pwwkew"
</strong><strong>Output: 3
</strong><strong>Explanation: The answer is "wke", with the length of 3.
</strong>Notice that the answer must be a substring, "pwke" is a subsequence and not a substring.
</code></pre>

&#x20;

**Constraints:**

* `0 <= s.length <= 5 * 104`
* `s` consists of English letters, digits, symbols and spaces.

## Intuition

```
Approach:

Sliding Window using HAsh MAp
```

### Links

<https://leetcode.com/problems/longest-substring-without-repeating-characters/description/>

### Video Links

### Approach 1:

```
Slinding Window + MAp
```

{% code title="C++" lineNumbers="true" %}

```cpp
class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        unordered_map<char, int> mp;
        int low = 0, high = 0;
        int ans = 0;

        while(high<s.size()){
            if(mp.find(s[high]) == mp.end()){
                mp[s[high]]++;
            }
            else{
                while(s[low] != s[high]){
                    mp.erase(s[low]);
                    low++;
                }
                low++;
            }
            ans = max(ans, high-low+1);

            high++;
        }

        return ans;
    }
};
```

{% endcode %}

### Approach 2:

```
```

{% code title="C++" lineNumbers="true" %}

```cpp
```

{% endcode %}

### Approach 3:

```
```

{% code title="C++" lineNumbers="true" %}

```cpp
```

{% endcode %}

### Approach 4:

```
```

{% code title="C++" lineNumbers="true" %}

```cpp
```

{% endcode %}

### Similar Problems

###
