I have no experience in such things, so there is a possibility that there are better ways to do this, but I have some ideas that might be useful.
You are currently calculating all possible combinations, you should be able to modify your algorithm to make it so that you can eliminate some combinations without calculating them.
I would sort the array to start, which will allow you to eliminate some values without calculating them.
For example, if you have an array that looks like [1,2,4,5,9] and min = 11 and max = 14, then your algorithm checks 1 + 2,1 + 4,1 + 5,1 + 9 , then 2 + 4, 2 + 5, 2 + 9, 4 + 5, 4 + 9, before coming to an answer.
If instead you start with the highest number, first you can eliminate all possible 1 combinations by calculating 9 + 1, since 9 + 1 <= 11, it should be so that all other possible 1 combinations are not valid for the two sum total The same with all 2 possible combinations. If you add this logic to your code, you should have less unnecessary calculations, hoping to speed up your code.
source share