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.
Java version of this code if anyone wants it.
PS: Very simple and elegent logic btw pal. Thank you :) !
public static int getTotalX(List<Integer> a, List<Integer> b) {
Collections.sort(a);
Collections.sort(b);
int maxA = a.get(a.size()-1);
int minB = b.get(0);
int totalX = 0;
int currentVal = maxA;
while(currentVal <= minB) {
final int current = currentVal;
if(a.stream().allMatch(e->current % e == 0 || e % current == 0) &&
b.stream().allMatch(e->current % e == 0 || e % current == 0)) {
totalX++;
}
currentVal += maxA;
}
return totalX;
}
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 version of this code if anyone wants it. PS: Very simple and elegent logic btw pal. Thank you :) !