Mark As Completed Discussion

One Pager Cheat Sheet

  • We'll use an efficient method which has an O(n) time complexity and O(1) space complexity to find the longest substring without repeating characters in a string of length 100000 or less which only contains lowercase letters.
  • The problem of finding the longest substring with no repeated characters can be solved by manually checking every substring with a brute force approach.
  • Our optimized solution efficiently solves the problem with respect to time, while requiring very little extra space, by dynamically tracking the last seen character element and jumping straight to the next valid substring when a duplicate is spotted.
  • This algorithm finds the longest substring without duplicates by iterating through each character in the string and using lastPos to store the last occurrence of the character.
  • The time complexity of the algorithm discussed is O(n) and the space complexity is O(1) or, depending on the size of the alphabet, O(A).

This is our final solution.

To visualize the solution and step through the below code, click Visualize the Solution on the right-side menu or the VISUALIZE button in Interactive Mode.

JAVASCRIPT
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment

Great job getting through this. Let's move on.

If you had any problems with this tutorial, check out the main forum thread here.