Leaders in an Array
Medium 40 XPArrays
Commonly asked at Zoho, Amazon
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
- One line of space-separated integers.
- Output
- The leaders, space-separated.
Sample 1
Input
16 17 4 3 5 2
Output
17 5 2
Read input with input() (no prompt message) and print only the answer. Run tries the Input box; Submit checks all test cases.
Output Loading Python (first time takes a few seconds)
Press Run to see the result here.The solution unlocks after 3 submissions.