A leader is a value that is strictly greater than every value to its right. The last value is always a leader. Return the leaders in their original left-to-right order.
A simple solution compares each value with everything after it. It is correct but too slow for long lists. Make it fast.
Example 1
Input:
array_leaders([16, 17, 4, 3, 5, 2])
Output:
[17, 5, 2]
17, 5 and 2 are each bigger than everything to their right.
Example 2
Input:
array_leaders([5, 5, 5])
Output:
[5]
Equal values do not count: only the last 5 is a leader.
0 <= len(nums) <= 3 * 10**5-10**9 <= nums[i] <= 10**9No results yet
Run your code to check it against the examples, or submit to run every test.