Explanation for the article: www.geeksforgeeks.org/find-the... Read More: www.geeksforgeeks.org/find-th... This video is contributed by Harshit Jain.
Пікірлер: 31
@claytonroberts58814 жыл бұрын
Method 3 in JavaScript: function getOddOccurence(array){ var res = 0; for (let i=0; i
@soumyachoudhary3 жыл бұрын
Can we initialise the res value with res=ar[0]; for(i=1; i
@ishitagoel65567 жыл бұрын
Is there any operation to find even occurence of a number in an array?
@prashantdhyani85593 жыл бұрын
please expalin the logic of xor in code also how xor of 0 and 12 will occurr
@siddhantrkokate4 ай бұрын
it will be 12
@RelearningSchool4 ай бұрын
One confusion: xor is basically modulo operation. What do you mean by xor all elements. Modulo wrt what?
@ramalingareddychinta95756 жыл бұрын
can u expalin when more than 1 number are occuring odd no of times
@spicytuna086 жыл бұрын
for hashing solution, i guess C++ map data structure is used. any opinion on this?
@HendersonHarrisson3 жыл бұрын
yeah we can use unordered_map
@sqammerabbas38114 жыл бұрын
this algo is not working if 2 element having odd occurance i-e {1,2,1,2,1,2}
@kalagaarun96384 жыл бұрын
The question expicitly mentions that the number of odd times occurring elements are only 1.
@hermesmercuriustrismegistu48414 жыл бұрын
Thx a lot
@BikkiMahato6 жыл бұрын
There is a problem when you give input as {0,0} even zeros then it prints 0 which is wrong.
@Curtisjackson5019756 жыл бұрын
Read the question properly to understand the conditions of values inside the array.
@divyachowdhary25748 жыл бұрын
thank u...keep up with gud work...
@GeeksforGeeksVideos7 жыл бұрын
You're welcome, Divya!
@Bhatonia_Jaat3 жыл бұрын
ty so much for these videos ;-;
@spicytuna086 жыл бұрын
awesome algorithm.
@jaikumarbohara79644 жыл бұрын
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
@subhadeepchakraborty6814 жыл бұрын
The question reads the array should contain positive integers, so 0 should not be an element in the array.
@aleenareji89552 жыл бұрын
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)
@mohammadammar74852 жыл бұрын
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)
@wecan27293 жыл бұрын
class Solution{ public: int getOddOccurrence(int arr[], int n) { int res=0; for(int i=0;i
@josebernardo46993 жыл бұрын
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; }
@kaifahmad41313 жыл бұрын
XOR the great :)
@momomiasec10787 жыл бұрын
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
@GeeksforGeeksVideos7 жыл бұрын
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. :)
@momomiasec10787 жыл бұрын
thanks i got it; can you explain the logic how its work i dont understand in the video lecture
@killersam7 жыл бұрын
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
@shivshankarsingh39184 жыл бұрын
@@GeeksforGeeksVideos True, and if condition on one number occurring odd number of times is removed then hash map will be the best solution.