Skip to content

Instantly share code, notes, and snippets.

@oberhamsi
Last active December 6, 2022 18:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oberhamsi/21280dc86ccf0ac7cc8dca82b3a8f2ef to your computer and use it in GitHub Desktop.
Save oberhamsi/21280dc86ccf0ac7cc8dca82b3a8f2ef to your computer and use it in GitHub Desktop.
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