Nearest Smaller to the Left
For each position, print the position (1-based) of the NEAREST element to its left that is strictly smaller, or 0 if none exists.
Input: the first line has N; the second line has N integers.
Output: N integers: the nearest-smaller positions.
Constraints:
- 1 ≤ N ≤ 105
- |ai| ≤ 109
Sample Tests
Input 1
8 2 5 1 4 8 3 2 5
Output 1
0 1 0 3 4 3 3 7
Input 2
1 7
Output 2
0
Discussion (opens after you solve — no spoilers before)
No comments yet.