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.
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 →
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. Changeint max = b[b.length-1];
toint max = b[0];
and you save a lot of unnecessary work.