Consider some called and a sorted . What is the most efficient algorithm to find the index or value in the that is less than , and The closest to on the number line (assuming condition (i) has been satsified)?
For example this could be a problem setup:
long X = 500;
List<Long> foo = new Arraylist<Long>();
Collections.sort(foo); // It's always sorted.
I would like the algorithm to either return or to return the index associated with (in this case ).