Question bank › Monotonic Stack
Dsa Monotonic Stack Hard

Next Smaller Number

You are given an array of integers. Your task is to find the next smaller number for each element in the array. If there is no smaller number to its right, output -1 for that element. Input Format: - The first line contains an integer n (1 <= n <= 10^5), the number of integers. - The second line contains n space-separated integers. Output Format: - Output a single line containing n space-separated integers, representing the next smaller number for each element. Example: Input: 5 4 3 2 1 5 Output: 3 2 1 -1 -1

Key concepts

monotonic_stacknumbersarray

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.