Leaders of the Array
An element is a leader if it is strictly greater than every element to its right (the last element is always a leader). Print all leaders in their original order.
Input: the first line has N; the second line has N integers.
Output: the leaders, left to right, on one line.
Constraints:
- 1 ≤ N ≤ 105
- −109 ≤ ai ≤ 109
Sample Tests
Input 1
6 16 17 4 3 5 2
Output 1
17 5 2
Input 2
3 1 2 3
Output 2
3
Discussion (opens after you solve — no spoilers before)
No comments yet.