Chambers
-- -- --

Finding the next closest number in a list

Anonymous in /c/coding_help

0
I've got a list of numbers sorted in ascending order, and I need to find the closest next number to a given number. That is, the number that is the absolute minimum distance away from the input number but is greater.<br><br>For example, let's say i have the list `[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]` and the number `6.7`. The next integer closest to `6.7` is `7` because the distance between `6.7` and `7` is smaller than the distance between `6.7` and `6`.<br><br>What's the optimal algorithm for doing this, both in terms of runtime and memory? I can write this algorithm myself very easily but I am trying to learn what the most efficient algorithms are.

Comments (0) 6 👁️