Last active
December 6, 2022 18:11
-
-
Save oberhamsi/21280dc86ccf0ac7cc8dca82b3a8f2ef to your computer and use it in GitHub Desktop.
This file contains 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
const findSignal = (count, inputString) => { | |
const inputChars = inputString.split('') | |
const markerStartIdx = inputChars.findIndex((_, idx) => { | |
const chars = inputChars.slice(idx, idx + count); | |
const set = new Set(chars); | |
if (set.size === count) { | |
return true; | |
} | |
}) | |
return markerStartIdx + count; | |
} | |
console.log( | |
findSignal(4, inputString), | |
findSignal(14, inputString) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment