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
- Discussions
Sales by Match
Sales by Match
Sort by
recency
|
353 Discussions
|
Please Login in order to post a comment
`
int sockMerchant(int n, vector ar) { std::sort(ar.begin(),ar.end()); int pairs = 0;
}
`
C++ with basic code: int sockMerchant(int n, vector ar) { int n_pair = 0; int j = 0; stable_sort(ar.begin(), ar.end()); for (int i = 0; i < n; i++) { if ((ar[i + j] == ar[i+j+1]) && (j + i + 1 < n)) { n_pair += 1; j += 1; } } return n_pair; }
from collections import Counter
def sockMerchant(n, ar):
c++