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 Aaryan Subsequences And Great XOR solution

YASH PAL, 31 July 202413 February 2026
In this HackerEarth Aaryan, Subsequences And Great XOR problem solution Aaryan went to school like any usual day, The teacher asked his crush the following question. Given an array of numbers, First, she had to compute the XOR of all the subsequences that can be formed. Suppose each subsequence had their following XOR value that came out after computing -> {P[0], P[1], P[2], and so on up to P[2^n-1] subsequences in an array of n numbers}
 
Now, the resultant answer is computed by taking bitwise inclusive OR of all P[i]’s
 
Since Aaryan wants to impress his crush, He wants to compute the answer for this problem but since he is not so good at it, he turned to you for help.
 
 
HackerEarth Aaryan, Subsequences And Great XOR problem solution

 

 

HackerEarth Aaryan, Subsequences And Great XOR problem solution.

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <fstream>

using namespace std;

int n;
bool iff[32];

int main()
{
freopen("inp7.txt", "r", stdin);
freopen("out7.txt", "w", stdout);
int x;
scanf("%d", &n);
for ( int i = 0; i < n; i++ ) {
scanf("%d", &x);
for ( int j = 0; j < 30; j++ ) iff[j] = iff[j] | (x&(1<<j));
}
int ans = 0;
for ( int j = 0; j < 30; j++ ) {
if ( iff[j] ) ans += (1LL<<j);
}
printf("%dn", ans);
return 0;
}
 
 

Second solution

#include <cstdio>
#include <cmath>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <cassert>
#include <string>
#include <cstring>
#include <queue>

using namespace std;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define S(x) scanf("%d",&x)
#define P(x) printf("%dn",x)

typedef long long int LL;
int main() {
int n;
S(n);
assert(n >= 1 && n <= 1000000);
int ans = 0;
while(n--) {
int x;
S(x);
assert(x >= 1 && x <= 1000000000);

ans |= x;
}
P(ans);
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