Your free access ends in 7 days — and you haven’t tried it yet. Watch one algorithm run, start to finish. It takes about two minutes.

Try one problem
0
Problem

Longest Substring Without Repeats

LeetCode #3Medium
Variable-size sliding window over a string

Given a string, find the length of the longest contiguous substring that contains no repeated characters.

Asked atAmazonMetaBloombergAdobe
step 1 / 70
p
w
w
k
e
w
[0][1][2][3][4][5]
Brute force · restart on duplicate
1given s
2max_len ← 0
3for i ← 0 to n − 1:
4 seen ← ∅
5 for ji to n − 1:
6 if s[j] in seen: break
7 seen.add(s[j])
8 max_len = max(max_len, ji)
9return max_len
state
  • n6
  • s"pwwkew"

line 1Find the LENGTH of the longest contiguous substring with NO repeating characters.