
Problem
Solution
Submissions
Longest Substring Without Repeating Characters
Certification: Intermediate Level
Accuracy: 0%
Submissions: 0
Points: 10
Write a JavaScript 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 string "abcabcbb" contains multiple substrings without repeating characters.
- The longest substring without repeating characters is "abc" with length 3.
- Other substrings like "bca" and "cab" also have length 3, but no substring is longer.
- Therefore, the answer is 3.
- The string "abcabcbb" contains multiple substrings without repeating characters.
Example 2
- Input: s = "bbbbb"
- Output: 1
- Explanation:
- The string "bbbbb" consists of only one character repeated.
- The longest substring without repeating characters is "b" with length 1.
- Any substring longer than 1 would contain repeating characters.
- Therefore, the answer is 1.
- The string "bbbbb" consists of only one character repeated.
Constraints
- 0 ≤ s.length ≤ 5 * 10^4
- s consists of English letters, digits, symbols and spaces
- Time Complexity: O(n)
- Space Complexity: O(min(m,n)) where m is the size of the charset
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 the sliding window technique with two pointers (left and right)
- Maintain a set or map to track characters in the current window
- Expand the right pointer and add characters to the tracking structure
- When a duplicate is found, shrink the window from the left until no duplicates exist
- Keep track of the maximum window size encountered during the process