Skip to content
Programmingoneonone
Programmingoneonone
  • Engineering Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
    • 100+ C++ Programs
  • Solutions
    • HackerRank
      • Algorithms Solutions
      • C solutions
      • C++ solutions
      • Java solutions
      • Python solutions
    • Leetcode Solutions
    • HackerEarth Solutions
  • Work with US
Programmingoneonone
Programmingoneonone

HackerEarth Sherlock and XOR problem solution

YASH PAL, 31 July 202413 February 2026
In this HackerEarth Sherlock and XOR problem solution, You are given an array A1, A2…AN. You have to tell how many pairs (i, j) exist such that 1 ≤ i < j ≤ N and Ai XOR Aj is odd.
 
 
HackerEarth Sherlock and XOR problem solution

 

 

HackerEarth Sherlock and XOR problem solution.

#include <cstdlib>
#include <stdio.h>
#include <cstring>
#include <complex>
#include <vector>
#include <cmath>
#include <ctime>
#include <iostream>
#include <numeric>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <iomanip>
#include <utility>
#include <locale>
#include <sstream>
#include <string>
#include <istream>
#include <ostream>
#include<assert.h>

using namespace std;

#define FOR(i,n) for(i=0;i<n;i++)
#define FORI(i,a,n) for(i=a;i<n;i++)
#define FORC(it,C) for(it=C.begin();it!=C.end();it++)
#define scanI(x) scanf("%d",&x)
#define scanD(x) scanf("%lf",&x)
#define print(x) printf("%dn",x)
#define ll long long
#define number32 4294967296ull
#define MAX 100001
#define len(s) s.length()
#define ff first
#define ss second
#define IN(A, B, C) (B) <= (A) && (A) <= (C)
#define AIN(A, B, C) assert(IN(A, B, C))
using namespace std;

typedef map<int,int> Mii;
typedef map<char,int> Mci;
typedef pair<int,int> Pii;
typedef vector<int> vi;
typedef vector<int> vc;
typedef vector<ll> vl;

typedef map<int,int>::iterator Miii;
typedef map<char,int>::iterator Mcii;

ll A[MAX+1];
int main()
{
int t,i;
int n;
cin>>t;
AIN(t,1,10);
ll ceven,codd;
ll ans;
while(t--)
{
ceven=0;
codd=0;
cin>>n;
AIN(n,1,100000);
FOR(i,n)
{
cin>>A[i];
AIN(A[i],0,1000000000);
if(A[i]%2==0)
{
ceven++;
}
else codd++;

}
ans=ceven*codd;
cout<<ans<<endl;
}
return 0;
}
 
coding problems solutions HackerEarth HackerEarth

Post navigation

Previous post
Next post

Leave a Reply

Your email address will not be published. Required fields are marked *

Programmingoneonone

We at Programmingoneonone, also known as Programming101 is a learning hub of programming and other related stuff. We provide free learning tutorials/articles related to programming and other technical stuff to people who are eager to learn about it.

Pages

  • About US
  • Contact US
  • Privacy Policy

Practice

  • Java
  • C++
  • C

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2026 Programmingoneonone | WordPress Theme by SuperbThemes