Message on Whatsapp 8879355057 for DSA(OA + Interview) + Fullstack Dev Training + 1-1 Personalized Mentoring to get 10+LPA Job
0 like 0 dislike
2,150 views
in Online Assessments by Expert (46,090 points)
reshown by | 2,150 views

2 Answers

1 like 0 dislike
Best answer

CODE:

typedef long long int ll ;

long gg(vector <int> parcels, int k) {
    
    unordered_map <ll,ll> gg ;
    int i = 0 ;
    while(i<parcels.size()) {
        gg[parcels[i]]++;
        i++;
    }
    
    int n = parcels.size();
    int ii = n ;
    //cout<<ii<<"\n";
    i = 1 ; ll rm = 0 ;
    while(i<=2000000+55){
        if(gg[i]==0 && ii<k) {
            //cout<<i<<"\n";
            rm = rm + i ;
            ii++;
        }
        
        i++;
    }
    
    return rm ;
    
    
}
by Expert (46,090 points)
edited by
0 like 0 dislike

Images of ques

imageimageimage


 

by Expert (46,090 points)
0 0
#include<iostream>
#include<bits/stdc++.h>
using namespace std;

int main()
{
    vector<int>arr{2,3,6,10,11};
    int n=arr.size();
    int k=9;
unordered_map<int,int>mapping;
for(auto i:arr)
{
mapping[i]++;
}
    long long int  cost=0;
    
    long long int i=1;
    while(i<INT_MAX and n<k)
    {
   if(mapping[i]==0)
{
cost+=i;
n++;
}

     i++;
    }

    cout<<cost;
}