#K35827. Next Taller Student
Next Taller Student
Next Taller Student
You are given a list of positive integers representing the heights of students standing in a line. For each student, your task is to determine the height of the next taller student standing to their right. If there is no taller student, output -1 for that position.
More formally, if the list of heights is \( H = [h_1, h_2, \dots, h_n] \), then for each \( i \) (from 1 to \( n \)) find the smallest index \( j \) such that \( j > i \) and \( h_j > h_i \). If such a \( j \) exists, output \( h_j \); otherwise, output \( -1 \).
Input and output instructions: The input is read from standard input (stdin) and the output should be written to standard output (stdout). See the input and output specifications below for details.
inputFormat
The first line of input contains a single integer \( n \), the number of students. The second line contains \( n \) space-separated integers representing the heights of the students.
Note: If \( n = 0 \), no further input is provided and the output should be empty.
outputFormat
Output a single line with \( n \) space-separated integers where the \( i^{th} \) integer is the height of the next taller student to the right of the \( i^{th} \) student. If there is no taller student, output \( -1 \) for that position.
## sample5
10 4 6 3 8
-1 6 8 8 -1