Nov-30-2020, 08:36 PM
Once sorted, there are tools to find the the one you want efficiently, such as bisect.
On a list of 10000000 ints, my machine took about 0.3 seconds to scan the list linearly and find the max value less than a target. It took 2 seconds to sort the list, but afterward bisect could find the highest value less than a target in 0.0001 seconds.
On a list of 10000000 ints, my machine took about 0.3 seconds to scan the list linearly and find the max value less than a target. It took 2 seconds to sort the list, but afterward bisect could find the highest value less than a target in 0.0001 seconds.