Problems > Leaders of the Array

Leaders of the Array

Difficulty: 1300 3000 ms 128 MB

implementation

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

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.