Ad
  • Default User Avatar

    And after that, try to do it with only one single pass over the input! That is, look at each character only once. ;-)

  • Default User Avatar

    Values in your variable first and second could very easily shoot beyond the range of int data type leading to overflow. As in worst case second=255*(256^3) + 255*(256^2) + 255*(256) + 255.
    Try after converting these variable to long.

  • Default User Avatar

    Test cases seems weak as most people solution are O(N^2). As a fun little challenge try to solve in O(N) complexity

  • Default User Avatar

    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.