1366. Rank Teams by Votes Medium
1/**
2 * [1366] Rank Teams by Votes
3 *
4 * In a special ranking system, each voter gives a rank from highest to lowest to all teams participated in the competition.
5 * 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 more teams are still tied after considering all positions, we rank them alphabetically based on their team letter.
6 * Given an array of strings votes which is the votes of all voters in the ranking systems. Sort all teams according to the ranking system described above.
7 * Return a string of all teams sorted by the ranking system.
8 *
9 * Example 1:
10 *
11 * Input: votes = ["ABC","ACB","ABC","ACB","ACB"]
12 * Output: "ACB"
13 * Explanation: Team A was ranked first place by 5 voters. No other team was voted as first place so team A is the first team.
14 * Team B was ranked second by 2 voters and was ranked third by 3 voters.
15 * Team C was ranked second by 3 voters and was ranked third by 2 voters.
16 * As most of the voters ranked C second, team C is the second team and team B is the third.
17 *
18 * Example 2:
19 *
20 * Input: votes = ["WXYZ","XYZW"]
21 * Output: "XWYZ"
22 * Explanation: X is the winner due to tie-breaking rule. X has same votes as W for the first position but X has one vote as second position while W doesn't have any votes as second position.
23 *
24 * Example 3:
25 *
26 * Input: votes = ["ZMNAGUEDSJYLBOPHRQICWFXTVK"]
27 * Output: "ZMNAGUEDSJYLBOPHRQICWFXTVK"
28 * Explanation: Only one voter so his votes are used for the ranking.
29 *
30 *
31 * Constraints:
32 *
33 * 1 <= votes.length <= 1000
34 * 1 <= votes[i].length <= 26
35 * votes[i].length == votes[j].length for 0 <= i, j < votes.length.
36 * votes[i][j] is an English uppercase letter.
37 * All characters of votes[i] are unique.
38 * All the characters that occur in votes[0] also occur in votes[j] where 1 <= j < votes.length.
39 *
40 */
41pub struct Solution {}
42
43// problem: https://leetcode.com/problems/rank-teams-by-votes/
44// discuss: https://leetcode.com/problems/rank-teams-by-votes/discuss/?currentPage=1&orderBy=most_votes&query=
45
46// submission codes start here
47
48impl Solution {
49 pub fn rank_teams(votes: Vec<String>) -> String {
50 String::new()
51 }
52}
53
54// submission codes end
55
56#[cfg(test)]
57mod tests {
58 use super::*;
59
60 #[test]
61 fn test_1366() {
62 }
63}
64
Back
© 2025 bowen.ge All Rights Reserved.