Last active
May 5, 2020 22:55
-
-
Save rakibulalam/44118e944efb3cedc094fc23a80f61b7 to your computer and use it in GitHub Desktop.
Luck Balance Hacker Rank
This file contains hidden or 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 luckBalance(k, contests) { | |
return contests.sort(([a,x],[b,y])=>y-x || b-a) | |
.reduce((memo,[l,t],key)=>{ | |
memo += t===1 && key<k? l: t===1 && key>=k?-l:l | |
return memo; | |
},0) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment