Question bank › Monotonic Stack
Dsa Monotonic Stack Easy

Popularity Surge

You are analyzing a sequence of numerical IDs. For each ID in the sequence, you want to find the first ID to its right that appears more frequently in the entire sequence. If multiple IDs appear the same number of times, only a strictly higher frequency counts. If no such ID exists, output -1. Example: IDs: [1, 2, 2, 1, 3] Frequencies: 1 occurs 2 times, 2 occurs 2 times, 3 occurs 1 time. - Index 0 (ID 1, freq 2): No ID to the right has freq > 2. Output -1. - Index 1 (ID 2, freq 2): No ID to the right has freq > 2. Output -1. - Index 2 (ID 2, freq 2): No ID to the right has freq > 2. Output -1. - Index 3 (ID 1, freq 2): No ID to the right has freq > 2. Output -1. - Index 4 (ID 3, freq 1): To the right is nothing. Output -1. Result: -1 -1 -1 -1 -1 Example 2: [3, 1, 2, 2, 1] Frequencies: 3:1, 1:2, 2:2 - Index 0 (ID 3, freq 1): First to right with freq > 1 is ID 1. Output 1. Result: 1 -1 -1 -1 -1

Key concepts

monotonic_stackhash_mapfrequency_analysis

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 Praxari's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.