Find the number which occurs odd number of times

  Рет қаралды 10,603

IDeserve

IDeserve

Күн бұрын

In an integer array, except for one number which occurs odd number of times, all other numbers occur even number of times. Find the number.
Example:
Input: 2 3 4 3 1 4 5 1 4 2 5
Output: 4
Algorithm:
Initialize result = 0.
Iterate over the array and XOR result with each element of the input array.
Once iteration over the array is done, print result as the output.
Order of the Algorithm:
Time Complexity: O(n)
Space Complexity: O(1)
Code and Algorithm Visualization:
Coming Soon on www.ideserve.co.in. Stay tuned!
Website: www.ideserve.co.in
Facebook: / ideserve.co.in

Пікірлер: 10
@IDeserve
@IDeserve 8 жыл бұрын
Dear Friends, If you like our content and would like us to continue making great content for you, please spread the word about IDeserve. A share/appreciation from you on social network would mean the world to us! Also, do like our Facebook page: facebook.com/IDeserve.co.in :) Thanks, -Team IDeserve.
@mamathagollavilli9
@mamathagollavilli9 3 жыл бұрын
Tnx
@umangbarbhaya1605
@umangbarbhaya1605 7 жыл бұрын
//java code class Test { public static void main(String args[]) { // x is stored using 32 bit 2's complement form. // Binary representation of -1 is all 1s (111..1) int a[] = {2,3,4,3,1,4,5,1,2,4,5}; int ans=a[0]; for(int i=1;i
@srinidhiii
@srinidhiii 7 жыл бұрын
awesome
@IDeserve
@IDeserve 7 жыл бұрын
Thanks Srinidhi for your kind words :) We would really appreciate if you could spread the word about IDeserve in your college and to your colleagues. Also please check out our website at: www.ideserve.co.in It has features like Algorithm Visualization, Learn Together and many more coming soon. Please check it out and leave us a comment there! Thanks, -Team IDeserve.
@ashishgupta8123
@ashishgupta8123 8 жыл бұрын
but for serching pairs it will take more than o(n)
@StockDC2
@StockDC2 7 жыл бұрын
I was thinking the same thing. If you need to find the same number in the array, wouldn't the time complexity be n^2?
@stalinsoft
@stalinsoft 7 жыл бұрын
since xor is commutative, you really no need to find the pair element. you just simply start 0 xor i'th element and take the result and xor with i+1'the element the final result value will be the answer.. this can be done in o(n). In this video he demonstrated picking the same element for the intuition reason.
@varun-bhandari
@varun-bhandari 8 жыл бұрын
Code Does not work for this input : {2, 7, 5, 4, 5, 2, 4, 3, 5, 2, 4, 4, 2, 7, 4, 4}; Returns '6' which is not even in the array.
@Horhew
@Horhew 8 жыл бұрын
That is because both 3 and 5 appear an odd number of times in your array.
Find the element that appears once in an array
7:49
IDeserve
Рет қаралды 30 М.
Shortest Range in K sorted lists
9:44
IDeserve
Рет қаралды 15 М.
WORLD BEST MAGIC SECRETS
00:50
MasomkaMagic
Рет қаралды 54 МЛН
Help Me Celebrate! 😍🙏
00:35
Alan Chikin Chow
Рет қаралды 47 МЛН
когда не обедаешь в школе // EVA mash
00:57
EVA mash
Рет қаралды 3,6 МЛН
Java Program to Find Number which Occurs Odd Number of Times in an Array
12:56
Programming Tutorials
Рет қаралды 3,5 М.
Maximum element from each subarray of size k
26:36
IDeserve
Рет қаралды 34 М.
Find the Number Occurring Odd Number of Times | GeeksforGeeks
6:28
GeeksforGeeks
Рет қаралды 46 М.
I used to hate QR codes. But they're actually genius
35:13
Veritasium
Рет қаралды 998 М.
Think Fast, Talk Smart: Communication Techniques
58:20
Stanford Graduate School of Business
Рет қаралды 40 МЛН
Maximum size square sub-matrix with all 1s
6:44
IDeserve
Рет қаралды 23 М.
The Boundary of Computation
12:59
Mutual Information
Рет қаралды 1 МЛН
WORLD BEST MAGIC SECRETS
00:50
MasomkaMagic
Рет қаралды 54 МЛН