Find the Number Occurring Odd Number of Times | GeeksforGeeks

  Рет қаралды 46,164

GeeksforGeeks

GeeksforGeeks

8 жыл бұрын

Explanation for the article: www.geeksforgeeks.org/find-the...
Read More: www.geeksforgeeks.org/find-th...
This video is contributed by Harshit Jain.

Пікірлер: 31
@claytonroberts5881
@claytonroberts5881 4 жыл бұрын
Method 3 in JavaScript: function getOddOccurence(array){ var res = 0; for (let i=0; i
@soumyachoudhary
@soumyachoudhary 3 жыл бұрын
Can we initialise the res value with res=ar[0]; for(i=1; i
@ishitagoel6556
@ishitagoel6556 7 жыл бұрын
Is there any operation to find even occurence of a number in an array?
@prashantdhyani8559
@prashantdhyani8559 3 жыл бұрын
please expalin the logic of xor in code also how xor of 0 and 12 will occurr
@siddhantrkokate
@siddhantrkokate 4 ай бұрын
it will be 12
@RelearningSchool
@RelearningSchool 4 ай бұрын
One confusion: xor is basically modulo operation. What do you mean by xor all elements. Modulo wrt what?
@ramalingareddychinta9575
@ramalingareddychinta9575 6 жыл бұрын
can u expalin when more than 1 number are occuring odd no of times
@spicytuna08
@spicytuna08 6 жыл бұрын
for hashing solution, i guess C++ map data structure is used. any opinion on this?
@HendersonHarrisson
@HendersonHarrisson 3 жыл бұрын
yeah we can use unordered_map
@sqammerabbas3811
@sqammerabbas3811 4 жыл бұрын
this algo is not working if 2 element having odd occurance i-e {1,2,1,2,1,2}
@kalagaarun9638
@kalagaarun9638 4 жыл бұрын
The question expicitly mentions that the number of odd times occurring elements are only 1.
@hermesmercuriustrismegistu4841
@hermesmercuriustrismegistu4841 4 жыл бұрын
Thx a lot
@BikkiMahato
@BikkiMahato 6 жыл бұрын
There is a problem when you give input as {0,0} even zeros then it prints 0 which is wrong.
@Curtisjackson501975
@Curtisjackson501975 6 жыл бұрын
Read the question properly to understand the conditions of values inside the array.
@divyachowdhary2574
@divyachowdhary2574 8 жыл бұрын
thank u...keep up with gud work...
@GeeksforGeeksVideos
@GeeksforGeeksVideos 7 жыл бұрын
You're welcome, Divya!
@Bhatonia_Jaat
@Bhatonia_Jaat 3 жыл бұрын
ty so much for these videos ;-;
@spicytuna08
@spicytuna08 6 жыл бұрын
awesome algorithm.
@jaikumarbohara7964
@jaikumarbohara7964 4 жыл бұрын
in the best solution you have given res = 0 then if 0 occurs odd no of time then also it will be cancelled due to initial 0
@subhadeepchakraborty681
@subhadeepchakraborty681 4 жыл бұрын
The question reads the array should contain positive integers, so 0 should not be an element in the array.
@aleenareji8955
@aleenareji8955 2 жыл бұрын
is this correct in any way?? arr=[1,2,3,1,3,2,3] arr_set=set(arr) for i in arr_set: if arr.count(i)%2!=0: print(i)
@mohammadammar7485
@mohammadammar7485 2 жыл бұрын
Yup but you are using an extra space of O(n) and list.count actually takes O(n) time and you are doing it for each element. So your time complexity will be O(n^2)
@wecan2729
@wecan2729 3 жыл бұрын
class Solution{ public: int getOddOccurrence(int arr[], int n) { int res=0; for(int i=0;i
@josebernardo4699
@josebernardo4699 3 жыл бұрын
function CounterTimes(arr){ let frequency = {}; let retorno = []; for(let item of arr){ if(item in frequency){ frequency[item] +=1 } else{ frequency[item] = 1; } } for(item in frequency){ if(frequency[item] % 2 !== 0){ retorno.push(item); } } return retorno; }
@kaifahmad4131
@kaifahmad4131 3 жыл бұрын
XOR the great :)
@momomiasec1078
@momomiasec1078 7 жыл бұрын
int ar[] = new int[]{2, 3, 5, 4, 5, 2, 4, 3, 5, 2, 4, 4, 2,2}; if add one more 2 at the end of the array it gives answer 7 which is rong
@GeeksforGeeksVideos
@GeeksforGeeksVideos 7 жыл бұрын
The problem states that given an array of positive integers. All numbers occur even number of times except one number which occurs odd number of times. Adding another 2 doesn't follow that. After inserting another 2 , there happen to be two numbers, 2 and 5, which appear odd number of times. Hope this solves your confusion. :)
@momomiasec1078
@momomiasec1078 7 жыл бұрын
thanks i got it; can you explain the logic how its work i dont understand in the video lecture
@killersam
@killersam 7 жыл бұрын
Xor--> 1st(I/P) 2nd(I/P) 0 0 -->0 0 1(A) -->1(A) 1(A) 0 -->1(A) 1 1 -->0 Any input with even occurrence integers will always give 0. E.g--> 1,2,3,1,2,3 In the loop ->0^1-->1 ->1^2->3 ->3^3->0 ->0^1->1 ->1^2->3 ->3^3->0 if u add 1 here it will return 1. Please follow below link stackoverflow.com/a/31673206/4914882
@shivshankarsingh3918
@shivshankarsingh3918 4 жыл бұрын
@@GeeksforGeeksVideos True, and if condition on one number occurring odd number of times is removed then hash map will be the best solution.
Pythagorean Triplet in an array | GeeksforGeeks
11:04
GeeksforGeeks
Рет қаралды 33 М.
Find the minimum distance between two numbers | GeeksforGeeks
15:56
GeeksforGeeks
Рет қаралды 65 М.
World’s Largest Jello Pool
01:00
Mark Rober
Рет қаралды 109 МЛН
Каха заблудился в горах
00:57
К-Media
Рет қаралды 10 МЛН
Learn Big O notation in 6 minutes 📈
6:25
Bro Code
Рет қаралды 220 М.
Secrets Hidden in Images (Steganography) - Computerphile
13:14
Computerphile
Рет қаралды 1,2 МЛН
Mastering Dynamic Programming - How to solve any interview problem (Part 1)
19:41
The Traveling Salesman Problem: When Good Enough Beats Perfect
30:27
Longest Span with same Sum in two Binary arrays | GeeksforGeeks
20:26
GeeksforGeeks
Рет қаралды 301 М.
Dijkstra's Algorithm - Computerphile
10:43
Computerphile
Рет қаралды 1,3 МЛН
IT`S VERIFIED!!! | "BUFFBATH" by RIOT
2:03
Neiro
Рет қаралды 114 М.
World’s Largest Jello Pool
01:00
Mark Rober
Рет қаралды 109 МЛН