/** more memory usage but this first solution came to my mind */
function sockMerchant(n, ar) {
let pairnum=0;
let arr =Array(101).fill(0);
for (let i=0 ; i<n;i++){
arr[ar[i]]++;
}
for (let i = 0 ; i<arr.length;i++){
if (arr[i]>=2){
pairnum+=Math.floor(arr[i]/2);
}
}
return pairnum;
}
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
/** more memory usage but this first solution came to my mind */
function sockMerchant(n, ar) {
let pairnum=0;
}