Algorithms and Data Structures · Middle · Question 18 of 75

Longest substring without repeating characters: what's the O(n) idea?

Explanation

Store the last index of each character in a map. When the current character was seen inside the window, jump the left edge to last + 1. Each index moves forward only, so the total work is O(n).

Further reading

Problem with a question

Algorithms and Data Structures · Middle · question 18

Test yourself

Take the Algorithms and Data Structures · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz