we are getting i/p of 5,00,000 numbers ranging from 0 to 10^9 one by one. all numbers appears twice except one. We have to tell that number in the most efficient way. Any idea or just a hint to get this ? no code, no algo nothing i want. i want just a simple hint from you. thanks.
I_m_rude
Recommended Answers
Jump to PostXor all the numbers as you input them. at the end you will left with the number occurs once.
Jump to PostXor all the numbers as you input them. at the end you will left with the number occurs once.
Can you elaborate on that? A couple examples please?
Jump to Postif we have an array 3,1,3,2,2
then do xor all the numbers start with 0.
0^3 = 3
3^1 = 2
2^3 = 1
1^2 = 3
3^2 = 11 is the ans. works only if all numbers occurs twice and only one number occurs once.
All 10 Replies
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
I_m_rude
shanki himanshu
27
Light Poster
WaltP
commented:
Nice! Didn't know that!
+14
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
I_m_rude
commented:
first time, god of C asking a question :D
+2
shanki himanshu
27
Light Poster
Ancient Dragon
commented:
slick :)
+14
WaltP
2,905
Posting Sage w/ dash of thyme
Team Colleague
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
WaltP
2,905
Posting Sage w/ dash of thyme
Team Colleague
I_m_rude
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.