Longest Substring Without Repeating Characters
Given a string, find the longest substring without any repeating characters and return the length of it. The input string is guaranteed to be not null.
For example, the longest substring without repeating letters for "bcdfbd" is "bcdf", we should return 4 in this case.
High level
hashTable to track chars seen and their last seen index
for each char in string
if not in HT:
curmax += 1
update globalmax
add char, index into HT
if is in HT:
get index of char
curmax = current index - index of repeated char
for 0 to index of repeated char: HT.remove(String.charAt(i))
Last updated
Was this helpful?