Skip to content
Programmingoneonone
Programmingoneonone
  • 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

HackerEarth Determining numbers problem solution

YASH PAL, 31 July 2024
In this HackerEarth Determining numbers problem solution you are given an array of integers. The special property of the array is that exactly two different elements occur once while other elements occur twice. you are required to determine those two elements.
HackerEarth Determining numbers problem solution

HackerEarth Determining numbers problem solution.

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define double long double
#define mod 1000000007
#define maxN 1000005
#define pb push_back
#define mp make_pair
#define mset(dp,val) memset(dp,val,sizeof dp);
#define pii pair<int,int>
#define pip pair<int,pii>
#define vi vector<int>
#define vpi vector<pii >
#define endl "n"
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define FOR(a,b,c) for(int(a) = b;a<=c;a++)
#define repr(a,b,c) for(int(a) = b;a>=c;a--)
#define rep(i,n) for(int(i) = 0;i<n;i++)
#define fir first
#define sec second
#define beg begin()
#define e end()
#define len length()
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
const int inf = 0x3f3f3f3f3f3f3f3fll;
int modExpo(int x,int y){
int res = 1;
while(y > 0){
if(y&1)
res = (res*x)%mod;
y = y>>1;
x = (x*x)%mod;
}
return res;
}
int modInverse(int a,int m){
int m1 = m;
int y = 0,x = 1;
if(m == 1)return 0;
while(a > 1){
int q = a/m;
int t = m;
m = a%m,a = t;
t = y;
y = x - q*y;
x = t;
}
if(x < 0)x+=m1;
return x;
}
int arr[maxN];
int32_t main(){
fastIO;
int n;
cin>>n;
rep(i,n)cin>>arr[i];
int xo = 0;
rep(i,n)xo^=arr[i];
int lo = 0;
while(true){
if((1ll<<lo)&xo)break;
lo++;
}
int tester = 1ll<<lo;
int setBit = 0,unSetBit = 0;
rep(i,n){
if(tester&arr[i])setBit^=arr[i];
else unSetBit^=arr[i];
}
if(setBit > unSetBit)swap(setBit,unSetBit);
cout<<setBit<<' '<<unSetBit;
return 0;
}

Second solution

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int maxn = 1e6 + 14;

int n;
bool mark[maxn];
int main(){
ios::sync_with_stdio(0), cin.tie(0);
cin >> n;
for(int i = 0; i < n; i++){
int x;
cin >> x;
mark[x] ^= 1;
}
for(int i = 1; i < maxn; i++)
if(mark[i])
cout << i << ' ';
cout << 'n';
}
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