package leetcode;

import java.util.Arrays;
import java.util.List;

/**
 * https://leetcode.com/problems/get-watched-videos-by-your-friends/
 */
public class Problem1311 {
    public List<String> watchedVideosByFriends(List<List<String>> watchedVideos,
                                               int[][] friends,
                                               int id,
                                               int level) {

        return null;
    }

    public static void main(String[] args) {
        Problem1311 prob = new Problem1311();
        System.out.println(prob.watchedVideosByFriends(
            Arrays.asList(
                Arrays.asList("A", "B"), Arrays.asList("C"), Arrays.asList("B", "C"), Arrays.asList("D")
            ), new int[][]{{1, 2}, {0, 3}, {0, 3}, {1, 2}}, 0, 1)); // ["B","C"]
        System.out.println(prob.watchedVideosByFriends(
            Arrays.asList(
                Arrays.asList("A", "B"), Arrays.asList("C"), Arrays.asList("B", "C"), Arrays.asList("D")
            ), new int[][]{{1, 2, 3}, {0, 3}, {0, 3}, {0, 1, 2}}, 0, 1)); // ["B","D","C"]
        System.out.println(prob.watchedVideosByFriends(
            Arrays.asList(
                Arrays.asList("A", "B"), Arrays.asList("A", "B", "C"), Arrays.asList("B", "C"), Arrays.asList("D")
            ), new int[][]{{1, 2}, {0, 3}, {0, 3}, {1, 2}}, 0, 1)); // ["B","A","C"]
        System.out.println(prob.watchedVideosByFriends(
            Arrays.asList(
                Arrays.asList("A", "B"), Arrays.asList("C"), Arrays.asList("B", "C"), Arrays.asList("D")
            ), new int[][]{{1, 2}, {0, 3}, {0, 3}, {1, 2}}, 0, 2)); // ["D"]
    }
}

@@ -34,17 +34,101 @@
 il.Array
-s
+List;%0Aimport java.util.Arrays;%0Aimport java.util.Collections;%0Aimport java.util.HashMap
 ;%0Aimport
@@ -143,16 +143,38 @@
 il.List;
+%0Aimport java.util.Map;
 %0A%0A/**%0A *
@@ -535,29 +535,1276 @@
 ) %7B%0A
-%0A        return null;
+        Map%3CString, Integer%3E countMap = new HashMap%3C%3E();%0A        watchedVideos(watchedVideos, friends, id, level, 0, countMap);%0A        System.out.println(countMap);%0A        List%3CMap.Entry%3CString, Integer%3E%3E sorted = new ArrayList%3C%3E(countMap.entrySet());%0A        Collections.sort(sorted, (a, b) -%3E %7B%0A            int cmp = Integer.compare(a.getValue(), b.getValue());%0A            if (cmp == 0) %7B%0A                return a.getKey().compareTo(b.getKey());%0A            %7D%0A            return cmp;%0A        %7D);%0A        List%3CString%3E answer = new ArrayList%3C%3E();%0A        for (Map.Entry%3CString, Integer%3E e : sorted) %7B%0A            answer.add(e.getKey());%0A        %7D%0A        return answer;%0A    %7D%0A%0A    private static void watchedVideos(List%3CList%3CString%3E%3E watchedVideos,%0A                                      int%5B%5D%5B%5D friends, int id, int targetLevel, int level,%0A                                      Map%3CString, Integer%3E countMap) %7B%0A        if (level == targetLevel) %7B%0A            for (String video : watchedVideos.get(id)) %7B%0A                countMap.put(video, countMap.getOrDefault(video, 0) + 1);%0A            %7D%0A            return;%0A        %7D%0A        for (int friend : friends%5Bid%5D) %7B%0A            watchedVideos(watchedVideos, friends, friend, targetLevel, level + 1, countMap);%0A        %7D
 %0A   

Update problem 1311