Show Buttons
Share On Facebook
Share On Twitter
Share On Google Plus
Share On Linkdin
Share On Reddit
Contact us
Hide Buttons

Length of Longest Substring Without Repeating Characters

Example

Given “bbb”, the answer is 1.

Given “pwwke”, the answer is 3.

Algorithm

Time complexity: O(n)

  1. Have a pointer which tracks the starting index of the current substring
  1. Create a map of each character and its index
    1. If the current character is in the lookup
      1. Change the starting index
  1. Add the current character to the map
  1. Update the max length of the substring


Solution


 

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *