Question bank › Monotonic Stack
Dsa Monotonic Stack Hard

Next Greater Frequency

Given an array of integers, find the next greater frequency for each unique number. The frequency is defined as the number of times a number appears in the array. For each number in the array, you should return the first number that has a higher frequency than it. If no such number exists, return -1 for that number. Print the results in the order of the original array. Example: Input: 5 3 1 3 2 1 2 1 Output: 3 -1 3 -1 -1 2 2 -1 Input format: A single line containing space-separated integers for the array. Output format: A single line containing space-separated integers, representing the next greater frequency for each corresponding number.

Key concepts

monotonic_stackarray

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.