Skip to content
CampusEduX

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.

Related Problems

  • Next Greater Element
    Medium · java, python, c, cpp, javascript
    Solve Problem
  • Min Stack
    Medium · java, python, c, cpp, javascript
    Solve Problem
  • Evaluate Postfix Expression
    Medium · java, python, c, cpp, javascript
    Solve Problem

Input (stdin)

Output

Run your code to see output here...