Skip to content

Instantly share code, notes, and snippets.

@dmdeluca
Created April 12, 2022 13:19
Show Gist options
  • Save dmdeluca/4c63d8bd570c83472d9f0299b5a33b1d to your computer and use it in GitHub Desktop.
Save dmdeluca/4c63d8bd570c83472d9f0299b5a33b1d to your computer and use it in GitHub Desktop.
PseudoCode for the Longest Substring Problem
int maxLength
int maxStart
int start
some set S
for each character C in the input string
check if this character is a repeated character (look for C in S)
if it is, repeat this:
look at the first character in my candidate substring.
remove that character from the front of the substring. (increment start)
remove that character also from S.
if that character I just removed was the same as C, break out of this loop.
add C to S.
if the set count (s.Count) is greater than maxLength, do:
set maxLength to the current set count
set maxStart to start
return the substring starting at maxStart with maxLength characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment