diff --git a/Cpp/leader-array.cpp b/Cpp/leader-array.cpp new file mode 100644 index 0000000..f202c84 --- /dev/null +++ b/Cpp/leader-array.cpp @@ -0,0 +1,33 @@ +#include +using namespace std; + +class Solution{ + + //Function to find the leaders in the array. + + public: + + vector leaders(int a[], int n){ + + // Code here + vector vec; + int max = a[n-1]; + vec.push_back(max); + + for(int i=n-2;i>=0;i--) + { + + if(a[i]>=max ) + + { + max=a[i]; + vec.push_back(a[i]); + } + + } + + reverse(vec.begin(), vec.end()); + + return vec; + } +}; \ No newline at end of file