Created
July 19, 2022 19:18
-
-
Save bruteforceboy/b30bf8a6f48b5f9c0656348b9c0df52c to your computer and use it in GitHub Desktop.
Longest string of non repeating characters problem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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