Skip to content
Programmingoneonone
Programmingoneonone

Learn everything about programming

  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
    • Cybersecurity
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programmingoneonone
Programmingoneonone

Learn everything about programming

HackerEarth Aaryan Subsequences And Great XOR solution

YASH PAL, 31 July 2024
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

Post navigation

Previous post
Next post

Are you a student and stuck with your career or worried about real-time things, and don't know how to manage your learning phase? Which profession to choose? and how to learn new things according to your goal, and land a dream job. Then this might help to you.

Hi My name is YASH PAL, founder of this Blog and a Senior Software engineer with 5+ years of Industry experience. I personally helped 40+ students to make a clear goal in their professional lives. Just book a one-on-one personal call with me for 30 minutes for 300 Rupees. Ask all your doubts and questions related to your career to set a clear roadmap for your professional life.

Book session - https://wa.me/qr/JQ2LAS7AASE2M1

Pages

  • About US
  • Contact US
  • Privacy Policy

Follow US

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