I there an O(n) algorithm for finding minimal distance between numbers in an one dimensional array? Does it matter if all the numbers are positive or negative? The array is not sorted
Printable View
I there an O(n) algorithm for finding minimal distance between numbers in an one dimensional array? Does it matter if all the numbers are positive or negative? The array is not sorted
Yes, there is O(n) algo to solve it.
Well, one approach would be to use Radix sort and then find the answer in a single pass over the sorted array.