Oh yes! Couldn’t think of that…Thanks
Excellent. How did you come up with that? Why does it work?
I used a similar approach but not O(n). I think it is correct because there will exist a number different than itself to pair it with if occurrence of a number is less than half of the size of the array. On the other hand if a number repeats more than n/2 times you cannot find a number to pair it with after (size - maxcount) times. Hope you understood why it is right.
I used a different approch to calculate count and CodeChef: Practical coding for everyone is the link to my solution.
excellent
Thanks for sharing this. I learned something new today
1 Like
nice approach