16. Longest Substring Without Repeating Characters

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

Example 1:

Input : S = "abcddabac"

Output : 4

Explanation : The answer is "abcd" , with a length of 4.

Example 2:

Input : S = "aaabbbccc"

Output : 2

Explanation : The answers are "ab" , "bc". Both have maximum length 2.

Now Your Turn!

Pick the correct output for the given input

Input : S = "aaaa"

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1 <= S.length <= 5*104
  • S contains only English lowercase letters.

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

0
class Solution{
public:
int longestNonRepeatingSubstring(string& s){
//your code goes here
}
};
Test Case

Input:

S