You are viewing a single comment's thread. Return to all comments →
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; }
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++ 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; }