I was asked this question in an interview recently.
Given an int array where all but one numbers appear once and exactly one number appears 3 times. Find that number in O(1) space and O(n) time complexity.
How do i approach this question?
I was asked this question in an interview recently.
Given an int array where all but one numbers appear once and exactly one number appears 3 times. Find that number in O(1) space and O(n) time complexity.
How do i approach this question?
Simply sort the array and find the answer.
Note: Since the array has integer values you can use Radix sort algorithm which has linear time-complexity. Moreover, you can use it as an in-place algorithm.
PS: The thrice is the illusion data and the original problem was the interviewee can think as simple as sorting problem. How much this expectation is fair is respect to the level of interview!