Solution: Rank Teams by Votes
Explore how to implement a voting system that ranks teams based on the number of votes across all positions. Learn to apply a 2D array to track vote counts per rank, handle ties by comparing subsequent ranks, and finalize sorting alphabetically. This lesson empowers you to build an optimized solution for multi-level ranking problems with clear time and space complexity analysis.
We'll cover the following...
Statement
Assume a ranking system where each gives a rank to all competing teams from highest to lowest. The final ranking is decided on the basis of the number of first-place votes they receive. If there’s a tie for first place, the second-place votes are used to break the tie; if there’s still a tie, the third-place votes are considered, and this continues until all positions have been evaluated. If teams remain tied after all positions have been reviewed, they are ranked alphabetically by their team names.
Given an array of strings votes that represents the rankings given by all voters, sort the teams according to the specified ranking system and return a string that lists all the teams in the ranked order.
Constraints:
votes.length...