Interview Query

How Many Friends

0
Have you seen this question before?

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

Next question: 2X - Y
.....
Python 3.9.6
Loading editor
Use Shift + Enter to run code