Created
May 30, 2019 17:37
-
-
Save kenmueller/0553b2b4af4a49411e1b18406f0db6aa to your computer and use it in GitHub Desktop.
Competition problem used in a Microsoft interview in JavaScript
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 duplicate = arr => { | |
const ordered = Array(arr.length).fill(false) | |
for (let i = 0; i < arr.length; i++) { | |
const element = arr[i] | |
if (ordered[element]) | |
return element | |
ordered[element] = true | |
} | |
} | |
console.log(duplicate([1, 3, 3, 2, 4])) // Ran 0.08s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment