using namespace std;
OUTPUT :: 24 40 50
An element in an array X is called a leader if it is greater than all elements to the right of it in X.
Starting from back 24 is a leader.
Now , 20 < 24 hence not a leader
Now what we are doing is keeping a record of the maximum element found in our right subarray and
We are checking if our current element under check is greater than this maximum element,If so that means that element is greater than all the elements to its right and hence a leader.
For example ::
When we reach 40.. Lead=24(max till now) ,since 40>24 the maximum it implies it is greater than all elements to its right and hence 40 is a Leader. Similarly for 50.