Skip to content

Instantly share code, notes, and snippets.

@kenmueller
Created May 30, 2019 17:37
Show Gist options
  • Save kenmueller/0553b2b4af4a49411e1b18406f0db6aa to your computer and use it in GitHub Desktop.
Save kenmueller/0553b2b4af4a49411e1b18406f0db6aa to your computer and use it in GitHub Desktop.
Competition problem used in a Microsoft interview in JavaScript
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