package leetcode;

import java.util.HashMap;
import java.util.Map;

/**
 * https://leetcode.com/problems/rank-teams-by-votes/
 */
public class Problem1366 {
    public String rankTeams(String[] votes) {
        Map<Integer, Map<Character, Integer>> map = new HashMap<>();
        for (String vote : votes) {
            for (int i = 0; i < vote.length(); i++) {
                if (!map.containsKey(i)) {
                    map.put(i, new HashMap<>());
                }
                map.get(i).put(vote.charAt(i), map.get(i).getOrDefault(vote.charAt(i), 0) + 1);
            }
        }
        System.out.println(map);
        return null;
    }

    public static void main(String[] args) {
        Problem1366 prob = new Problem1366();
        System.out.println(prob.rankTeams(new String[]{"ABC","ACB","ABC","ACB","ACB"})); // "ABC"
        System.out.println(prob.rankTeams(new String[]{"WXYZ","XYZW"})); // "XWYZ"
//        System.out.println(prob.rankTeams(new String[]{"ABC","CBA"})); // "ABC"
//        System.out.println(prob.rankTeams(new String[]{"ABDC","CDBA"})); // "ACBD"
//        System.out.println(prob.rankTeams(new String[]{"CBDA","ADBC"})); // "ACBD"
//        System.out.println(prob.rankTeams(new String[]{"WYXZ","XYZW"})); // "XWYZ"
//        System.out.println(prob.rankTeams(new String[]{"ZMNAGUEDSJYLBOPHRQICWFXTVK"})); // "ZMNAGUEDSJYLBOPHRQICWFXTVK"
//        System.out.println(prob.rankTeams(new String[]{"BCA","CAB","CBA","ABC","ACB","BAC"})); // "ABC"
//        System.out.println(prob.rankTeams(new String[]{"M","M","M","M"})); // "M"
    }
}

@@ -55,19 +55,67 @@
 va.util.
-Map
+HashSet;%0Aimport java.util.Map;%0Aimport java.util.Set
 ;%0A%0A/**%0A 
@@ -290,17 +290,85 @@
 teger%3E%3E 
-m
+rankMap = new HashMap%3C%3E();%0A        Map%3CCharacter, Set%3CInteger%3E%3E charM
 ap = new
@@ -492,17 +492,21 @@
    if (!
-m
+rankM
 ap.conta
@@ -538,17 +538,21 @@
         
-m
+rankM
 ap.put(i
@@ -605,17 +605,21 @@
         
-m
+rankM
 ap.get(i
@@ -640,17 +640,21 @@
 rAt(i), 
-m
+rankM
 ap.get(i
@@ -709,48 +709,285 @@
     
-%7D%0A        %7D%0A        System.out.println(m
+    if (!charMap.containsKey(vote.charAt(i))) %7B%0A                    charMap.put(vote.charAt(i), new HashSet%3C%3E());%0A                %7D%0A                charMap.get(vote.charAt(i)).add(i);%0A            %7D%0A        %7D%0A        System.out.println(rankMap);%0A        System.out.println(charM
 ap);

Update problem 1366