You are viewing a single comment's thread. Return to all comments →
Typescript
function sockMerchant(n: number, ar: number[]): number { const socks = ar.sort((a,b)=>a-b); let result = 0; let last = socks[0]; let pair = 0; for(let sock of socks) { if(sock === last) pair++; else { result += pair%2 === 0 ? (pair)/2 : (pair-1)/2; pair = 1; } last = sock; } result += pair%2 === 0 ? (pair)/2 : (pair-1)/2; return result; }
Seems like cookies are disabled on this browser, please enable them to open this website
Sales by Match
You are viewing a single comment's thread. Return to all comments →
Typescript