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 Determining numbers problem solution

YASH PAL, 31 July 202413 February 2026
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 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