Message on Whatsapp 8879355057 for DSA(OA + Interview) + Fullstack Dev Training + 1-1 Personalized Mentoring to get 10+LPA Job
0 like 0 dislike
4,826 views
in Online Assessments by Expert (110,460 points)
edited by | 4,826 views

1 Answer

0 like 0 dislike
Best answer

Video solution :

Link to problem for submitting : https://www.hackerrank.com/contests/desiqna-oa-practice-contest-00/challenges/a-356

C++ code solution :
#include <cmath>
#include <cstdio> 
#include <vector>
#include <iostream> 
#include <algorithm>
#include <bits/stdc++.h>
using namespace std; 
typedef long long int ll ; 
int main() 
{ ll n; 
cin>>n; 
ll x[n+1]={0}; 
ll y[n+1]={0};
ll i = 1 ; 
while(i<=n){
    cin>>x[i]; 
    i++; 
    }
    i = 1 ; 
    while(i<=n)
    { 
        cin>>y[i]; 
        i++;
    } 
    ll kk[n+1]={0}; 
    i = 1; 
    while(i<=n)
    {
        //cout<<x[i]<<" "<<y[i]<<"\n"; 
        kk[i] = ((x[i])^(y[i]));
        i++;
    }
    unordered_map <ll,ll> bb ; 
    bb[0]=0; 
    ll goodrm = 0 ;
    i = 1 ; 
    ll oo = 0 ;
    while(i<=n) {
        oo = ((oo)^(kk[i])) ;
        if(bb.find(oo)==bb.end()){
            bb[oo] = i ; 
            
        } else { ll G = abs(i-bb[oo]) ; goodrm = max(G,goodrm); 
            
        } 
        i++; 
        
    }
    
    cout<<goodrm ; 
    return 0;
}
by Expert (110,460 points)
selected by