You are viewing a single comment's thread. Return to all comments →
Here is O(n) solution without sorting:
function twoArrays(k, A, B) { const sumA = A.reduce((a,v) => a += (v > k) ? k : v, 0) const sumB = B.reduce((a,v) => a += (v > k) ? k : v, 0) return (A.length && sumA + sumB >= k * A.length) ? 'YES' : 'NO' }
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 →
Here is O(n) solution without sorting: