Skip to content
CampusEduX

Next Greater Element

Mediumjavapythonccppjavascript

For every element of an array, find the first element to its right that is strictly greater. 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 greater element for each position, separated by single spaces.

Related Problems

  • Next Smaller 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...