0
arrays
Write a program to print all the leaders in the array. An element is leader if it is greater than all the elements to its right side. And the rightmost element is always a leader. For example in the array {16, 17, 4, 3, 5, 2}, leaders are 17, 5 and 2.
1 Answer
0
O(n) solution in C++:
https://code.sololearn.com/cKlU8bAi6dug/#cpp
n is the length of the array.
The idea is to simply find the maximum but starting from the right side of the array. Every time you update your max, just print it.