Deque<Integer> deque = new LinkedList<>();
h[0] = -1;
deque.offerFirst(0);
for (int i = 1; i <= n; i++) {
while (h[i] <= h[deque.peekFirst()]) deque.pollFirst();
l[i] = deque.peekFirst();
deque.offerFirst(i);
}