Question: Amazon Online Assessment | Longest Sub-List | Time taken to execute the Process | 2023
1
Entering edit mode

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

//  Code quesiton 1

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

        map<int,int> mp;

        for(auto var:vect) mp[var]++;

        int ans=0;

        for(auto var:mp) {
            int num=var.first;
            int freq=var.second;

            while(freq--) {
                ans+=num;
                num=ceil((float)num/2);
            }
        }

        cout << ans << endl;

ADD COMMENTlink 15 months ago sumeet kumar sahoo • 290
1
Entering edit mode

Code Question 2

void solve()
{
    int n;
    cin>>n;

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

    vector<int> len(n,0);
    len[n-1] = 0;

    for(int i = n-2;i>=0;i--){
        if(a[i]>=a[i+1]){
            len[i] = len[i+1] + 1;
        }
    }

    auto p = max_element(len.begin(),len.end());
    int max_ele = *p;
    int start = 0;
    int end = 0;
    for(int i = 0;i<n;i++){
        if(len[i] == max_ele){
            start = i;
            end = i+len[i];
        }
    }

    for(int i = start;i<=end;i++){
        cout<<a[i]<<" ";
    }
    cout<<endl;
}
 

ADD COMMENTlink 15 months ago Dhruv jain • 50

Login before adding your answer.

Similar Posts
Loading Similar Posts