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.
publicstaticintgetTotalX(List<Integer>a,List<Integer>b){// Write your code hereintoutputCounter=0;Collections.sort(a);Collections.sort(b);intmin=a.get(0);intmax=b.get(b.size()-1);intselectedNumber=min;booleanfirstArrayCheck=false;booleansecondArrayCheck=false;for(inti=min;i<=max;i+=1){for(intj=0;j<a.size();j++){if(selectedNumber%a.get(j)==0){// do nothingfirstArrayCheck=true;}else{firstArrayCheck=false;break;}}if(firstArrayCheck){for(intj=0;j<b.size();j++){if(b.get(j)%selectedNumber==0){// do nothingsecondArrayCheck=true;}else{secondArrayCheck=false;break;}}}if(firstArrayCheck&&secondArrayCheck)outputCounter++;// Resetting ArrayChecksfirstArrayCheck=false;secondArrayCheck=false;selectedNumber+=1;}returnoutputCounter;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Between Two Sets
You are viewing a single comment's thread. Return to all comments →
Here is my Java Code :