src.longest_subs_no_repeat

Classes

Solution()

class src.longest_subs_no_repeat.Solution[source][source]
lengthOfLongestSubstring(s: str) int[source]

Thought process

  • Basic sliding window concept

  • We move l left if we notice a repeated letter s[r] untill the condition is no longer violated

  • If the repeated condition is not violated l is stationary marking the start of our substring and we grow the sliding window from the right side with r

  • Two key things to know here are : sliding window approach with left and right pointers sliding across our array, character map

Notes

  • time complexity : \(O(n)\)

  • space complexity : \(O(n)\) because of subs hashset