Question bank › Monotonic Stack
Dsa Monotonic Stack Medium

Next Greater Customer Interaction

You are a customer service manager, and you want to analyze customer interaction durations. Given an array of integers representing the duration of each customer interaction in seconds, you need to find the next greater interaction duration for each interaction. If there is no greater duration that occurs after an interaction, use -1. Write a program that reads an integer n (the number of interactions) followed by n integers representing the interaction durations. Print a single line with n integers representing the next greater interaction durations. Input format: - The first line contains a single integer n (1 <= n <= 100000). - The second line contains n space-separated integers, where each integer is between 0 and 10^6 (inclusive). Output format: - A single line with n space-separated integers, the next greater durations. Example: Input: 5 3 7 4 5 2 Output: 7 -1 5 -1 -1

Key concepts

monotonic_stackarraynext_greater_element

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.