Find Two Non Repeating Elements In An Array

preview_player
Показать описание
JOIN ME
—————

TUTORIALS PLAYLIST
————————————

INTERVIEW PLAYLIST
————————————

Time Lines
=========
0:05 Introduction
0:46 Approach

In this video we will learn how to get two non repeating elements from given array, actually this is same as finding one non repeating element from an array but with little trick.
I have explained that trick, This topic comes under bit manipulation.

#bits #bitmanipulation #dsa #algo #datastructure #interview
Рекомендации по теме
Комментарии
Автор

Please continue string, arrays problems as well..These two DS covers many questions.

hrithikrudra
Автор

int sum = 0, setbitpos= 0;
std::vector<int> onevec {0};
std:: vector<int> zerovec {0};

for(int i= 0; i<n ; i++)
{sum ^=arr[i];}

while(sum)
{setbitpos++;
if(sum&1) break;
sum= sum>>1;
}

int result= 0, final =0;
for(int j=0; j<n; j++) {
result = arr[j]>>setbitpos-1;
final = result&1;
if(final)
onevec.pushback(arr[j]);
else
zerovec.pushback(are[j]);
}

int firstno= 0, secondno=0;

for(auto first: onevec)
firstno ^=first;

for(auto second: zerovec)
secondno^=second;

pratikrahate
Автор

i can't understand this when both number even or both odd

mdtarikbosunia