public List<String> getRankedCourses(String user) {

        HashSet<String> attended = new HashSet<>(getAttendedCoursesForUser(user));
        HashSet<String> visitedFriends = new HashSet<>();
        Map<String, Integer> socialCourses = new HashMap<>();
        Queue<String> socialCircle = new LinkedList<>();

        socialCircle.add(user);
        visitedFriends.add(user);
        int deep = 0;
        while (!socialCircle.isEmpty() && deep < 3) {
            int size = socialCircle.size();
            deep++;
            for (int i = 0; i < size; i++) {
                String curUser = socialCircle.poll();
                List<String> friends = getDirectFriendsForUser(curUser);
                for (String friend : friends) {
                    if (!visitedFriends.contains(friend)) {
                        socialCircle.add(friend);
                    }
                }
                if (!visitedFriends.contains(curUser)) {
                    List<String> courses = getAttendedCoursesForUser(curUser);
                    for (String course : courses) {
                        if (!attended.contains(course)) {
                            if (socialCourses.containsKey(course)) {
                                socialCourses.put(course, socialCourses.get(course) + 1);
                            } else {
                                socialCourses.put(course, 1);
                            }
                        }
                    }
                    visitedFriends.add(curUser);
                }
            }
        }

        return sortByComparator(socialCourses);
    }