Longest Substring Without Repeating Characters | Rulcode
Loading problem details...
118. Longest Substring Without Repeating Characters
Medium
Topics
Companies
Hint
Understand Before Coding
Loading visualization...
Visualize This Problem
Open Visualizer
Draw Your Approach
Draw
Example 1:
Input:s = "abcabcbb"
Output:3
Explanation:The longest substring without repeating characters is "abc", with length 3.
Example 2:
Input:s = "bbbbb"
Output:1
Explanation:The longest substring without repeating characters is "b", with length 1.
Example 3:
Input:s = "pwwkew"
Output:3
Explanation:The longest substring without repeating characters is "wke", with length 3. Note that the answer must be a substring, "pwke" is a subsequence and not a substring.
Example 4:
Input:s = ""
Output:0
Explanation:An empty string has no substrings, so the length is 0.
Example 5:
Input:s = "dvdf"
Output:3
Explanation:The longest substring without repeating characters is "vdf", with length 3.
Constraints:
•
•
Time Complexity
O(n)
Space Complexity
O(min(m,n))
Step 1 / 40
Speed: 1.0x
Sliding Window Visualizer
p
w
w
k
e
w
Active Hash Set Memory (charSet)
Set is empty
Process Step
Initialize sliding window boundaries and character tracking set.