Skip to content

Instantly share code, notes, and snippets.

@davidjsalazarmoreno
Created March 16, 2021 17:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidjsalazarmoreno/05f3b73ee5bf55e1535d774d239a6f57 to your computer and use it in GitHub Desktop.
Save davidjsalazarmoreno/05f3b73ee5bf55e1535d774d239a6f57 to your computer and use it in GitHub Desktop.
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