Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
And after that, try to do it with only one single pass over the input! That is, look at each character only once. ;-)
Values in your variable
first
andsecond
could very easily shoot beyond the range ofint
data type leading to overflow. As in worst casesecond
=255*(256^3) + 255*(256^2) + 255*(256) + 255.Try after converting these variable to
long
.Test cases seems weak as most people solution are O(N^2). As a fun little challenge try to solve in O(N) complexity
few examples :
[1,2,1,5,2] -> 5
[4,4,4,5,1,1,10,2,5,10,2] -> 4
[9,0,-1,0,9,8,8,9,10,9,10,10,10] -> -1
Basically, input array would always have ONLY ONE integer with ODD number of occurences and every other integer in array(if any) would
always occur EVEN number of times. You are asked to find the integer that occurs ODD number of times.