Created
March 16, 2021 17:09
-
-
Save davidjsalazarmoreno/05f3b73ee5bf55e1535d774d239a6f57 to your computer and use it in GitHub Desktop.
Possible solution to https://www.hackerrank.com/challenges/sock-merchant/problem
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
var n = 9; | |
var ar = [10, 20, 20, 10, 10, 30, 50, 10, 20] | |
function sockMerchant(n, arr) { | |
const hash = new Map(); | |
let count = 0; | |
for(let i = 0; i < n; i++) { | |
const sock = arr[i]; | |
if (hash.get(sock) == 1) { | |
hash.set(sock, 0); | |
count += 1; | |
} else { | |
hash.set(sock, 1); | |
} | |
} | |
return count; | |
} | |
console.log(sockMerchant(n, ar)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment