#include<bits/stdc++.h>
using namespace std;
vector<int> printLeadersBruteForce(int arr[], int n) {
vector<int> ans;
for (int i = 0; i < n; i++) {
bool leader = true;
//Checking whether arr[i] is greater than all
//the elements in its right side
for (int j = i + 1; j < n; j++)
if (arr[j] > arr[i]) {
// If any element found is greater than current leader
// curr element is not the leader.
leader = false;
break;
}
// Push all the leaders in ans array.
if (leader)
ans.push_back(arr[i]);
}
return ans;
}
int main() {
// Array Initialization.
int n = 6;
int arr[n] = {10, 22, 12, 3, 0, 6};
vector<int> ans = printLeadersBruteForce(arr,n);
for(int i = 0;i<ans.size();i++){
cout<<ans[i]<<" ";
}
cout<<endl;
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnZlY3RvcjxpbnQ+IHByaW50TGVhZGVyc0JydXRlRm9yY2UoaW50IGFycltdLCBpbnQgbikgewoKICB2ZWN0b3I8aW50PiBhbnM7CiAgCiAgZm9yIChpbnQgaSA9IDA7IGkgPCBuOyBpKyspIHsKICAgIGJvb2wgbGVhZGVyID0gdHJ1ZTsKCiAgICAvL0NoZWNraW5nIHdoZXRoZXIgYXJyW2ldIGlzIGdyZWF0ZXIgdGhhbiBhbGwgCiAgICAvL3RoZSBlbGVtZW50cyBpbiBpdHMgcmlnaHQgc2lkZQogICAgZm9yIChpbnQgaiA9IGkgKyAxOyBqIDwgbjsgaisrKQogICAgICBpZiAoYXJyW2pdID4gYXJyW2ldKSB7CiAgICAgICAgICAKICAgICAgICAvLyBJZiBhbnkgZWxlbWVudCBmb3VuZCBpcyBncmVhdGVyIHRoYW4gY3VycmVudCBsZWFkZXIKICAgICAgICAvLyBjdXJyIGVsZW1lbnQgaXMgbm90IHRoZSBsZWFkZXIuCiAgICAgICAgbGVhZGVyID0gZmFsc2U7CiAgICAgICAgYnJlYWs7CiAgICAgIH0KCiAgICAvLyBQdXNoIGFsbCB0aGUgbGVhZGVycyBpbiBhbnMgYXJyYXkuCiAgIC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