Question: Airtel, Online Assessment Bank (13th September 2023) | Superior Array element | Cost to Company
0
Entering edit mode

ADD COMMENTlink 15 months ago Delta 2.9k
1
Entering edit mode

//SUPERIOR ARRAY ELEMENT

#include<bits/stdc++.h>
using namespace std;

int helper(vector<int> &v){

    int n = v.size();
    int cnt = 1; //last element always counted

    vector<int> maxi(n);
    maxi[n-1] = v[n-1];

    for(int i=n-2; i>=0; i--){
        if(v[i]>maxi[i+1]){
            cnt++;
            maxi[i] = v[i];
        }
        else{
            maxi[i] = maxi[i+1];
        }
    }

    return cnt;

}


int main(){
    
    int n;
    cin>>n;

    vector<int> v(n);
    for(int i=0; i<n; i++){
        cin>>v[i];
    }

    cout<<helper(v)<<endl;

    return 0;

}

ADD COMMENTlink 4 months ago hehehaha • 10

Login before adding your answer.

Similar Posts
Loading Similar Posts