--DAY 13--
Hi, I am going to make #100DaysOfCode Challenge. Everyday I will try solve 1 problem from leetcode or hackerrank. Hope you can go with me until end.
Now let's solve problem today:
- Problem: Sales by Match
- Detail: here
- Idea: sort then check each pair in array.
- My solution (javascript):
function sockMerchant(n, ar) {
let count=0,i=0;
ar.sort((a,b)=>a-b);
while(ar.length>=2){
if(ar[0]==ar[1]){
count++;
ar.splice(0,2);
}
else{
ar.shift();
}
}
return count;
}
-->If you have better solution or any question, please comment below. I will appreciate.
Top comments (2)
/** more memory usage but this first solution came to my mind */
function sockMerchant(n, ar) {
let pairnum=0;
}
Good luck, I'm doing #100DaysofCode as well!
dev.to/rammina/100-days-of-code-an...