Message on Whatsapp 8879355057 for DSA(OA + Interview) + Fullstack Dev Training + 1-1 Personalized Mentoring to get 10+LPA Job
0 like 0 dislike
3,275 views

All tcs nqt codes for all batches available in group @tcs_nqt_ans : https://telegram.im/@tcs_nqt_ans

Link to all the TCS_NQT Coding Questions and Answers of year 2022 : https://www.desiqna.in/tag/tcs_nqt

in Online Assessments by Expert (110,460 points)
edited by | 3,275 views

2 Answers

0 like 0 dislike
Best answer

C++ Code : 

#include <bits/stdc++.h>

using namespace std;
typedef long long int ll ; 
int main(){
    ll n ; 
    cin>>n;vector <ll> b ; 
    ll r ; 
    cin>>r;
    ll i = 0 ; 
    while(i<=n-1){
        ll yy;
        cin>>yy;
        b.push_back(yy);
        i++;
    }
    i = 0 ; 
    while(i<=r-1){
        ll yy;
        cin>>yy;
        b.push_back(yy);
        i++;
    }
    
    
    
    sort(b.begin(),b.end());
    
    cout << fixed << setprecision(2) ;
    ll g = n + r ; 
    if(g%2==0){
        long double vv = 2 ; 
        long double kk = double(b[g/2] + b[g/2 - 1])/vv;
        cout<<kk;
    }
    else{
        long double kk = b[g/2];
        cout<<kk ; 
    }
    
}
by Expert (110,460 points)
edited by
1 like 0 dislike
#include <bits/stdc++.h>

using namespace std;
typedef long long int ll ;
int main(){
    ll n ;
    cin>>n;vector <ll> b ;
    ll r ;
    cin>>r;
    ll i = 0 ;
    while(i<=n-1){
        ll yy;
        cin>>yy;
        b.push_back(yy);
        i++;
    }
    i = 0 ;
    while(i<=r-1){
        ll yy;
        cin>>yy;
        b.push_back(yy);
        i++;
    }
    
    
    
    sort(b.begin(),b.end());
    
    
    ll g = n + r ;
    if(g%2==0){
        long double vv = 2 ;
        long double kk = double(b[g/2] + b[g/2 - 1])/vv;
        std::cout << std::fixed << std::setprecision(2)<<kk;
    }
    else{
        long double vv=b[g/2];
        std::cout << std::fixed << std::setprecision(2) <<vv ;
    }
    
}
by (200 points)
edited by
0 0
Thanks..man ......