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.

Thanks for this solution! I realized that
int i=min;i<=max;i++ iterates all the way to the highest value in b, which is unnecessary, as the largest possible factor of values in array b is the smallest value in it. Change int max = b[b.length-1]; to int max = b[0]; and you save a lot of unnecessary work.

The solution is very much helpful!!But "x" has to lie between the max value in array a and min value in arra y b.hence the values of min and max could be int min=a[a.length-1] and int max = b[0];This will reduce the time for processing the code.

## Between Two Sets

You are viewing a single comment's thread. Return to all comments →

Thanks for this solution! I realized that

`int i=min;i<=max;i++`

iterates all the way to the highest value in b, which is unnecessary, as the largest possible factor of values in array b is the smallest value in it. Change`int max = b[b.length-1];`

to`int max = b[0];`

and you save a lot of unnecessary work.The solution is very much helpful!!But "x" has to lie between the max value in array a and min value in arra y b.hence the values of min and max could be int min=a[a.length-1] and int max = b[0];This will reduce the time for processing the code.

This is true just tested. So ideal range is

`int min = a[a.length-1]; int max = b[0];`

:) :)