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){intresult=0;intmaxOfA=Collections.max(a);intminOfB=Collections.min(b);// Find divisibles by aSet<Integer>set=newHashSet<>();for(inti=maxOfA;i<=minOfB;i++){intcountOfDivisibles=0;for(intx:a)if(i%x==0)countOfDivisibles++;if(countOfDivisibles==a.size())set.add(i);}// Check if each of divisible set > divides each of bfor(intfactor:set){intcount=0;for(intx:b)if(x%factor==0)count++;if(count==b.size())result++;}returnresult;}
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 →
Java