The Next Different Number
InterviewTime limit1sMemory limit1024 MB
For each position i in a sequence, find the smallest later index j whose value differs from A[i], or -1 if none exists.
- Level
Easy3 of 10
- Topics
- Array, Implementation, Greedy
- Solved
- No attempts yet
Problem
A sequence of length , , is given. For each integer with , output the smallest integer such that and . If no such exists, output .
Input
The first line gives , the size of the sequence . The second line gives separated by spaces. ,
Every number in the input is an integer.
Output
For each , output the smallest that satisfies the condition. If no such exists, output .