ni niniinininininnnninniiniiiiniiniinininiiinininniiinn
OTSi - Object Technology Solutions India Pvt. Ltd
NIT Rourkela 2026
C++ - Default language
My Stats
EXP gained
4612
Level
5 (Champion)
Community stats
Discussions
0
0
Know more
65
Total problems solved
30
Easy
32
Moderate
3
Hard
0
Ninja

Current streak:

0 days

Longest streak:

8 days

Less

More

Achievements
2
Ronin
Topics
Binary Search
+ 1 more
1
Samurai
Topics
Arrays
Discussions
better but using xor;
Interview problems
``````vector<int> findMissingRepeatingNumbers(vector < int > a) {

int n = a.size();
int xr=0 ,one = 0 , zero = 0;

for (int i = 0 ; i<n ; ++i){
xr = xr ^ a[i] ^ (i+1);
}

int bit_no = 0;
while (1){
if ((xr & (1<<bit_no)) != 0)
break;

bit_no++;
}

for (int i = 0 ; i<n ;++i ){
if ((a[i] & (1<<bit_no)) != 0)
one = one ^ a[i];

else {
zero = zero ^ a[i];
}

if (((i+1) & (1<<bit_no)) != 0)
one ^= i+1;
else
zero ^= i+1;
}

int cnt = 0;
for (int i = 0 ; i<n ; ++i){
if (one == a[i]){
cnt++;
if (cnt == 2){
return {one , zero};
}
}
}
return {zero , one};
}``````
vasude_v
Published On 29-Jul-2023
70 views
0 replies