title: Search sorted List<Long> for closest and less than
body: <p>Consider some <code>long</code> called <code>X</code> and a sorted <code>List&lt;Long&gt;</code>. What is the most efficient algorithm to find the index or value in the <code>List&lt;Long&gt;</code> that is <strong>(i)</strong> less than <code>X</code>, and <strong>(ii)</strong> The closest to <code>X</code> on the number line (assuming condition (i) has been satsified)? </p>
  
  <p>For example this could be a problem setup:</p>
  
  <pre><code>long X = 500;
  List&lt;Long&gt; foo = new Arraylist&lt;Long&gt;();
  foo.add(450L);
  foo.add(451L);    
  foo.add(499L);
  foo.add(501L);
  foo.add(550L);
  
  Collections.sort(foo); // It's always sorted.
  </code></pre>
  
  <p>I would like the algorithm to either return <code>499</code> or to return the index associated with <code>499</code> (in this case <code>i=2</code>). </p>