Skip to content
Programmingoneonone
Programmingoneonone
  • Home
  • CS Subjects
    • IoT ? Internet of Things
    • Digital Communication
    • Human Values
  • 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

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

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes