30. Winner of an Election

The problem can be found at the following link: Question Link

My Approach

In this problem, I used an unordered map to count the occurrences of each candidate. Then I iterated through the map to find the candidate with the maximum votes, considering lexicographical order in case of a tie.

Time and Auxiliary Space Complexity

  • Time Complexity: O(n), where n is the number of votes.

  • Auxiliary Space Complexity: O(c), where c is the number of unique candidates.

Code (C++)

Contribution and Support

For discussions, questions, or doubts related to this solution, please visit our discussion section. We welcome your input and aim to foster a collaborative learning environment.

If you find this solution helpful, consider supporting us by giving a ⭐ star to the getlost01/gfg-potd repository.

Last updated

Was this helpful?