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.
publicstaticStringtwoArrays(intk,List<Integer>A,List<Integer>B){// sort A in ascending order and B in descending orderCollections.sort(A);Collections.sort(B);Collections.reverse(B);// check if permutation satisfies relation >= kintsatisfy=0;for(inti=0;i<A.size();i++){satisfy+=(A.get(i)+B.get(i)>=k)?1:0;}Stringquery=(satisfy==A.size())?"YES":"NO";returnquery;}
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 →
java solution