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.
int getTotalX(vector a, vector b) {
int n = a.size(); int m = b.size();
//setting the number to be checked to be 'between two arrays' as maximum element from array a
int x = *max_element(a.begin(), a.end());
int count = 0;
//iterators to check if x satisfies given conditions for all elements of array a and b
int ia = 0, ib = 0;
//maximum allowed value of a is minimum element of array b, for it to be a factor of elements of b
while(x <= *min_element(b.begin(),b.end())){
for(int i = 0; i < n; i++){
if(x%a[i] == 0) ia++;
}
for(int i = 0; i < m; i++){
if(b[i]%x == 0) ib++;
}
if(ia == n && ib == m) count++;
//resetting values of iterators to check for next value of x
ia = 0; ib = 0;
x++;
}
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 →
//Solution
int getTotalX(vector a, vector b) { int n = a.size(); int m = b.size();
}