Question bank › Monotonic Stack
Dsa Monotonic Stack Medium

Next Greater Element II

Given a circular list of integers, you need to find the next greater element for each element in the list. The next greater element for an element x is the first greater element to its right in the list. If there is no greater element, you should return -1 for that element. Remember, since the list is circular, if you reach the end, continue searching from the start of the list. Input format: - The first line contains an integer n (1 <= n <= 100000), the number of elements. - The second line contains n space-separated integers. Output format: - Print a single line containing n space-separated integers representing the next greater element for each element. Example: Input: 5 1 2 1 3 2 Output: 2 3 3 -1 -1

Key concepts

monotonic_stackcircular_arraysnext_greater

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.