---
# System prepended metadata

title: Write in any language you want. Java.

---

# Write in any language you want. Java.
# Social network

# GIVEN TO YOU
get_friends(user_id: int) -> [int]{

}

# WANT TO WRITE
get_recommended_friends(user_id: int, k: int) -> [int] {
    # mutual friend
    # sorted by most number of mutual friends
    # k recommendations. k = 5, top 5 recommendations
    []int result 
    list friends = get_friends(A)
    for (f : friends) {
        int[] indirectFriends = get_friends(user_id: int)
        if (f.id in indirectFriends) {
            continue
        } else {
            if size(resulte) < k {
                result.add(f.id)
            }
            
        }
    }
}

A --> B --> C
A --> D --> C
A --> G --> E

get_friends(A) --> B, D, G
get_friends(C) --> B, D
get_friends(B) --> A, C

C has TWO mutual friends B and D
E has ONE mutual friend G

get_recommended_friends(A) --> [C,E]
