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.
public static int getTotalX(List<Integer> a, List<Integer> b) {
/* Assuming the last value in 'a' is the maximum and
the first value in 'b' is the minimum */
int start = a.get(a.size()-1),end=b.get(0),count=0;
for (int i = start; i <= end; i+=start) {
boolean trueForA = true, trueForB = true ;
for (int num : a) {
if (i % num != 0) {
trueForA = false;
break;
}
}
for (int num : b) {
if(trueForA)
if (num % i != 0) {
trueForB = false;
break;
}
}
if (trueForA && trueForB) {
count++;
}
}
return count;
}
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 Solution **