3 ms·
I really like majority voting algorithm to get majority number in array which appears more then half of the elements, Its the most simplest and elegant algorith
by haidrali 10y ago
I really like majority voting algorithm to get majority number in array which appears more then half of the elements, Its the most simplest and elegant algorithm i have studied
http://www.geeksforgeeks.org/majority-element/ http://www.geeksforgeeks.org/majority-element/
- sameera_sy 10y agoI'm surprised how the solution doesn't have the hashmap implementation of it, which gives out o(n) and is much more simple. But the algorithm is interesting though!
- haidrali 10y ago@sameera_sy thats the point hash map solution will take O(n) space complexity as well consider a situation where you need memory efficient solution