We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Sales by Match
Sales by Match
Sort by
recency
|
6049 Discussions
|
Please Login in order to post a comment
I want to recieve feedback about my solution in Javascript. How can I do it better?:
Java
C# Solution
Grouping up each socks and then just divide each group by 2. In C#, when a mathematical operation would result in a floating-point number for integer, the decimal would be concatenated. So if Sock 1 has 5 socks, divided by 2 it would result in 2 pairs - which is correct. Probably could optimize the loop further but the idea was there.
def sockMerchant(n, ar): # Write your code here count=0 y= Counter(ar) for i in y.values(): t=int(i/2) count+=t * return count
def sockMerchant(n, ar): # Write your code here count=0 y= Counter(ar) for i in y.values(): t=int(i/2) count+=t * return count