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.
My Java solution with o(n log n) time complexity and o(1) space complexity:
publicstaticStringtwoArrays(intk,List<Integer>A,List<Integer>B){// goal: order arrs a and b to where a[i] + b[i] >= k//order arr a ascending, order arr b descendingCollections.sort(A);Collections.sort(B,Collections.reverseOrder());//check each valfor(inti=0;i<A.size();i++){if(A.get(i)+B.get(i)<k)return"NO";}return"YES";//all vals of A and B were > k when summed together}
Cookie support is required to access HackerRank
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 →
My Java solution with o(n log n) time complexity and o(1) space complexity: