Find the leaders in a list
Coding problemEasy-Medium
A value in a list is a leader when it is strictly greater than every value to its right. The last value is always a leader, because nothing is to its right.
Given a list of integers, return all leaders in the order they appear in the list. An empty list has no leaders.
Examples
Example 1
Input: nums = [16,17,4,3,5,2]
Output: [17,5,2]
Example 2
Input: nums = [5,5,5]
Output: [5]
The first two 5s are not strictly greater than the 5 after them.
Example 3
Input: nums = [1,2,3,4]
Output: [4]
Constraints
- The list holds between 0 and 300,000 integers
- Each value is a 32-bit integer
Run checks the 3 examples. Submit also runs the hidden tests: edge cases, large inputs and a time limit.
Run your code to see the results here. Ctrl or Cmd + Enter runs; add Shift to submit.