5.Majority Element
Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋
times.
Solution I: (Using Sorting)
Time Complexity: O(n log(n) ) , Space Complexity: O(1)
Solution II: (Using Hashmaps)
Time Complexity: O(n) , Space Complexity: O(n)
Solution III: (Optimized Solution using Moore's Voting Algo
)
Moore's Voting Algo
) Time Complexity: O(n) , Space Complexity: O(1)
Last updated
Was this helpful?