You are viewing a single comment's thread. Return to all comments →
C++ sort either A or B and sort in reverse order in case of the other one. By doing so, we guarantee that the added pair were optimized.
string twoArrays(int k, vector A, vector B) {
sort(A.begin(), A.end(), greater<int>()); sort(B.begin(), B.end()); int n = A.size(); for(int i = 0; i < n; ++i) { if(k > A[i] + B[i]) { return "NO"; } } return "YES";
}
Seems like cookies are disabled on this browser, please enable them to open this website
Permuting Two Arrays
You are viewing a single comment's thread. Return to all comments →
C++ sort either A or B and sort in reverse order in case of the other one. By doing so, we guarantee that the added pair were optimized.
string twoArrays(int k, vector A, vector B) {
}