Skip to content

Instantly share code, notes, and snippets.

@bruteforceboy
Created July 19, 2022 19:18
Show Gist options
  • Save bruteforceboy/b30bf8a6f48b5f9c0656348b9c0df52c to your computer and use it in GitHub Desktop.
Save bruteforceboy/b30bf8a6f48b5f9c0656348b9c0df52c to your computer and use it in GitHub Desktop.
Longest string of non repeating characters problem
function longestNonRepeating(a, b, c) {
list = [
[a, 'a'],
[b, 'b'],
[c, 'c']
].sort()
if (list[2][0] > list[1][0] + list[0][0] + 1) {
return "none"
}
var result = ""
while (list[2][0] > 0) {
result += list[2][1]
--list[2][0]
if (list[1][0] > 0) {
result += list[1][1]
--list[1][0]
}
list.sort()
}
return result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment