Look Up
InterviewTime limit1sMemory limit128 MB
For each cow, find the smallest index j > i with H_j > H_i, or print 0 if none exists.
- Level
Medium4 of 10
- Topics
- Stack, Array, Implementation
- Solved
- No attempts yet
Problem
Farmer John's cows (), conveniently numbered , are standing in a row. Cow has height ().
Each cow looks toward the cows with higher index numbers. We say cow "looks up" to cow if and . For each cow , determine the index of the first cow in the row (the one with the smallest index) that cow looks up to.
Input
- Line 1: a single integer .
- Lines 2 to : line contains the single integer .
Output
- Lines 1 to : line contains the smallest index of a cow that cow looks up to. If no such cow exists, print .
Hint
Cows and both look up to cow ; cows and both look up to cow ; and cows and do not look up to any cow.