My issue
how to solve this question
My code
#include <iostream>
#include <math.h>
using namespace std;
int dectobinary(int n){
int i=0;
cout<<"ENTER the value of n ";
cin>>n;
int ans=0;
while(n!=0){
int bit=n&1;
ans=bit*pow(10,i)+ans;
i++;
n=n>>1;
return ans;
}
int main()
while(T--){int n;
dectobinary(n);
}
return 0;
}
Problem Link: MINMXOR Problem - CodeChef
@shobhit14
there is a concept of prefix and suffix .
which is used in the problem
U have to precompute the prefix and suffix xor of the whole array and store it in some data structure .
And then use it to compute your actual answer.
This is my c++ code for reference
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<algorithm>
#include<numeric>
using namespace std;
typedef long long int lli;
using namespace __gnu_pbds;
template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//typedef long long int lli;
//typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> multi_pbds;
//typedef tree<pair<int , int>, null_type, less<pair<int ,int>>, rb_tree_tag, tree_order_statistics_node_update> pbdsp;
//typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#define nl "\n";
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define db long double
#define prq priority_queue<lli>
#define psq priority_queue<lli,vector<lli>,greater<lli>>
#define mod 1000000007
#define lb lower_bound
#define ub upper_bound
#define vlli vector<lli>
#define mslli multiset<lli>
#define inf 1e17
#define sp " "
#define pb push_back
#define pie 3.14159265358979323846
#define test lli t; cin>>t; while(t--)
int32_t main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
test{
lli n;
cin>>n;
lli a[n];
map<lli,lli> mp,mpb;
lli x=0;
for(lli i=0;i<n;i++)
{
cin>>a[i];
x=x^a[i];
mp[i]=x;
}
x=0;
for(lli i=n-1;i>=0;i--)
{
x=x^a[i];
mpb[i]=x;
}
lli ans=mp[n-1];
for(lli i=0;i<n;i++)
{
lli val=mp[i-1]^mpb[i+1];
ans=min(ans,val);
}
cout<<ans<<endl;
}
}