Interview Query

How Many Friends

Start Timer

0:00:00

Upvote
13
Downvote
Save question
Mark as completed
View comments (21)
Next question

You are given a list of lists where each group represents a friendship.

For example, given the list:

list = [[2,3],[3,4],[5]]

Person 2 is friends with person 3, person 3 is friends with person 4, etc. 

Write a function to find how many friends each person has. 

Example: 1

Input:

friends = [[1,3],[2,3],[3,5],[4]]

Output:

[(1,1), (2,1), (3,3), (4,0), (5,1)]

Example: 2

Input:

friends = [[1],[2],[3],[4]]

Output:

[(1,0), (2,0), (3,0), (4,0)]

Explanation: every person has no friends on the friends list

.
.
.
.
.


Comments

Loading comments.