Skip to content
C

Next Smaller Element

Mediumjavapythonccppjavascript

For every element of an array, find the first element to its right that is strictly smaller. If no such element exists, use -1.

Input Format

The first line contains an integer N. The second line contains N space-separated integers.

Output Format

Print N values, the next smaller element for each position, separated by single spaces.

Input (stdin)

Output

Run your code to see output here...