Last active
December 6, 2018 00:58
-
-
Save tapmodo/a3f2ab38a73f5bb26b909ae0fb8d0a6c 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
function containsExactHalvesSubarray(v) { | |
const hash = {} | |
v = v.sort((a,b) => parseInt(a)-parseInt(b)); | |
v.forEach(i => { | |
if (i < 0) | |
if (hash[i]) hash[i][0] = true | |
else hash[i/2] = [null,true] | |
else | |
if (hash[i/2]) hash[i/2][1] = true | |
else hash[i] = [true,null] | |
}) | |
return Object.keys(hash).every(key => hash[key][0] == hash[key][1]) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment