Urgent.News

One page, thousands of outlets. See who else covered it.

Editions

Tech

1366. Rank Teams by Votes

Problem In a special ranking system, each voter gives a rank from highest to lowest to all teams participating in the competition. The ordering of teams is decided by who received the most position-one votes. If two or more teams tie in the first position, we consider the second position to resolve the conflict, if they tie again, we continue this process until the ties are resolved. If two or…

In a special ranking system, each voter assigns a rank from highest to lowest to all teams participating in the competition. The teams' order is determined by the number of first-place votes they receive. When two or more teams tie in the first position, the second position is considered to break the tie. This process continues until the ties are resolved.

If the teams remain tied after evaluating all positions, they are ranked alphabetically based on their team letter. The input is an array of strings, representing the votes of all voters in the ranking system. The task is to sort all teams according to the ranking system and return a string of all teams sorted by the ranking system.

The solution utilizes two data structures - a hashmap and a heap. The hashmap stores the votes for each team, while the heap sorts the teams based on the voting results. The comparator is used to sort the teams, and the heap is initialized accordingly. The votes are calculated by traversing the votes array and populating the hashmap.

Once the votes are calculated, the keys of the hashmap (the teams) are added to the heap, and the elements are pulled off one by one to generate the final sorted string.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

VoxelRank Server List

Why I Built VoxelRank: A Modern, Anti-Pay-to-Win Server Directory Finding a quality multiplayer server shouldn't feel like navigating a commercial billboard.

More from Wednesday 19 August →