How to find nearest number in a sequence that is strictly smaller than given number
Converting my comment into an answer.

Here is an algorithm for the interpretation that you are looking for $l_j$ such that $l_j \lt l_i$ and $|i-j|$ is the smallest.


  Traverse left to right, push stuff on stack. If new element to be pushed >= top
  element. If new element &lt; top element keep popping the stack till top
  &lt; new element. For the elements popped, the new element is the $l_j$