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.
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.
Cookie support is required to access HackerRank
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 →
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.