Playing Hacks and Stuffs!
We are given an array nums with an integer threshold. Our goal is to find a positive integer divisor which would divide all the elements in the array by it. If the sum of all the result is less than or equal to the threshold we should return the smallest divisor value
One thing we should note there is that the value of divisor does not nessary means it has to belong to the arrary nums as it can be greater than the maximum value in the array
Here’s the first approach I took in solving this:
divisor with the conditon in tact tends to be either less than or equal to the threshold value. What that means is that if the divisor used is the maximum value, when we then calculate the sum i.e array[i] / divisor the result tends to be less than or equal to the threshold value. So that means that the lower the value the higher the sum tends to be greater than the threshold valuelen(array)-1 I made set it to a value that is a multiple of the maximum element in the array and the threshold max(array) * threshold. Using that it allows the search to continue until it finds the smallest divisor that satisfies the condition, even if the threshold is greater than any element in the array.Solve Script: link