September 20, 2024
wp-header-logo-18.png
https://www.youtube.com/watch?v=_xqIp2rj8bo


Lecture 11 of DSA Series : (Array Part 4) – Majority Element | Brute- Better-Best Approach | Moore’s Voting Algorithm – Pair Sum …

20 thoughts on “Majority Element | Brute- Better-Best Approach | Moore's Voting Algorithm | & Pair Sum

  1. We can further optimize the sorting approch as the number appers more than n/2 times so it will always be at the n/2 index of the array so we can simply return the nums[n/2] there is no need to traverse tha array again

    O(nlogn + n)
    O(nlogn)

    I know they both are same time complexity but it is more optimized

    Code:

    sort(nums.begin(),nums.end());
    return nums[n/2];

    Pin it so everyone can see it.

Leave a Reply

Your email address will not be published. Required fields are marked *