Trains the technique from
LeetCode 1366Rank Teams by VotesThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
Each judge at a bake-off hands in a card ranking every entry from best to worst. An entry is written as one uppercase letter, and ballots[i] is the i-th judge's card, read left to right from their first place to their last. Every card lists exactly the same entries, each of them once.
The final table is worked out place by place. The entry named first on more cards finishes ahead. If two entries were named first on the same number of cards, whichever of them was named second on more cards finishes ahead, then third place is compared, and so on. If two entries have exactly the same count at every place, the one whose letter comes earlier in the alphabet finishes ahead.
Return the entries in final order as a single string.
Example 1
Each entry is named first on exactly one card, so first place is compared next: C is named second twice, B once and A never. The table therefore reads C, then B, then A.
Example 2
C is named first twice, A once and B never, which fixes the whole table as C, then A, then B.
Example 3
A and B are each named first once and second once, so their counts match at every place and the alphabet puts A ahead.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def rank_entries(ballots: list[str]) -> str:public String rankEntries(String[] ballots)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.