Frequency-Greater Next Element
Time limit1sMemory limit512 MB
For each position, find the nearest value to its right whose total frequency in the array exceeds the frequency of the current element, or -1 if none exists.
- Level
Medium5 of 10
- Topics
- Stack, Hash map, Array, Implementation
- Solved
- No attempts yet
Problem
There is a sequence of size . For each element of the sequence, we want to find its frequency-greater next element .
Let be the number of times appears in . The frequency-greater next element of is the leftmost number to its right whose number of appearances in is greater than . If no such number exists, the frequency-greater next element is .
For example, if , then , , , and . To the right of there is no number that appears more than 3 times, so . For , lies to its right and , so . We have , , and .
Input
The first line gives the size of the sequence (). The second line gives the elements of ().
Output
Print the numbers separated by spaces.