
Problem
Solution
Submissions
Longest Substring Without Repeating Characters
Certification: Intermediate Level
Accuracy: 0%
Submissions: 0
Points: 10
Write a C program to find the length of the longest substring without repeating characters in a given string. A substring is a contiguous sequence of characters within a string.
Example 1
- Input: s = "abcabcbb"
- Output: 3
- Explanation: The substring "abc" has a length of 3 with no repeating characters. There are several substrings without repeating characters: "a", "b", "c", "ab", "bc", "ca", "abc", etc. Among these, "abc" is one of the longest with a length of 3. Therefore, the output is 3.
Example 2
- Input: s = "bbbbb"
- Output: 1
- Explanation: The longest substring without repeating characters is "b" with a length of 1. All other substrings of length greater than 1 contain repeating characters. Therefore, the output is 1.
Constraints
- 0 ≤ s.length ≤ 5 * 10^4
- s consists of English letters, digits, symbols and spaces
- Time Complexity: O(n), where n is the length of the string
- Space Complexity: O(min(m,n)), where m is the size of the character set and n is the length of the string
Editorial
My Submissions
All Solutions
Lang | Status | Date | Code |
---|---|---|---|
You do not have any submissions for this problem. |
User | Lang | Status | Date | Code |
---|---|---|---|---|
No submissions found. |
Solution Hints
- Use a sliding window approach to track the current substring without repeating characters
- Maintain a set or hash table to check if a character exists in the current substring
- Use two pointers to represent the start and end of the current substring
- When you encounter a repeating character, move the start pointer to the right of the previous occurrence of that character
- Keep track of the maximum length encountered so far