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
|
6030 Discussions
|
Please Login in order to post a comment
Here is problem solution in Python, Java, C++, C and Javascript - https://programmingoneonone.com/hackerrank-sales-by-match-problem-solution.html
Here is my c++ solution , you can find the video explanation here : https://youtu.be/HPIhFXx_DVM
C++ solution Using Hashing. int sockMerchant(int n, vector ar) { map count; for(int i = 0; i < ar.size(); i++){ count[ar[i]]++; } int pairs = 0; for(auto p : count){ pairs += p.second/2; } return pairs; }
python
You don't need to parse the input as it is irrelevant, also that whole LINQ in the C# code gave me a headache:
And is totally unnecessary. Treat the second line of input as colours and try to add them in a HashSet. If you can add it, fine continue, if not remove it and increment a counter to count the pairs.