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,447 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 (108,280 points)
edited by | 3,447 views

3 Answers

0 like 0 dislike
Best answer

C++ working code : 

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll ; 

int main() {
    
    ll n;
    cin>>n; 
    vector <ll> b2(n+5,0),b5(n+5,0),answer(n+5,0);
    ll i = 1 ; 
    while(i<=n){
        cin>>b2[i];
        i++;
    }
    i = 1 ; 
    while(i<=n){
        cin>>b5[i];
        answer[i] = 3 ; //0...1...2...3.......
        i++;
    }
    
    ll kk = 0 ; 
    i = 32 ; 
    while(i>=0){
        ll j = 1 ; ll kq = 0 ; 
        vector <ll> tmp(n+5,0);
        while(j<=n){
            ll bit1 = 0 ;
            ll bit2 = 0 ;
            ll k = b2[j] >> i; 
            if (k & 1) {
              bit1 = 1 ;   
            } 
        else{
            bit1 = 0 ; 
        }
        k = b5[j] >> i; 
            
            if (k & 1) {
              bit2 = 1 ;   
            } 
        else{
            bit2 = 0 ; 
        }
        
        
        if(bit1==1 && bit2==1){
            //answer[j]======answer[j].....
            tmp[j] = answer[j] ; 
        } else if(bit1==1){
            
            if(answer[j]==3 || answer[j]==1){
            tmp[j] = 1 ; }
            else{
                kq = 1 ; 
            }
            
            
            
        } else if(bit2==1){
            //tmp[j] = 2 ; 
            
            if(answer[j]==3 || answer[j]==2){
            tmp[j] = 2 ; }
            else{
                kq = 1 ; 
            }
            
            
        }
        else{
            kq = 1 ; 
        }
        
        
            
            
            
            
            
            j++;
        }
        
        if(kq==0){
            
            answer = tmp ; 
            kk = kk + pow(2,i);
        }
        else{
            //fail........
        }
        
        
        
        
        i--;
    }
    
    cout<<kk; 
    cout<<" ";
    ll oo = 0 ; 
    i = 1 ; 
    while(i<=n){
        if(answer[i]==2){
            oo++;
        }
        i++;
    }
    cout<<oo ; 
    return 0 ; 
}
by Expert (108,280 points)
0 like 0 dislike

Image of the Question :: 

image

image

image

image

image

by Expert (34,270 points)
edited by
0 like 0 dislike

AND Question : (In short to point)

Given two arrays : F[N] and R[N] , you are allowed to use F[i] or R[i] in your final sequence of "N" elements . Maximize the value of Bitwise AND of the final sequence of "N" numbers. In the final output print 2 numbers : Maximum value and the number of times you were supposed to select R[i] instead of F[i] .. 

Exact images of the question will be uploaded soon.. 

by Expert (108,280 points)