Google|Onsite|USA|feb-2022
Anonymous User
5954

Company- Google
Interview- Onsite Round
YoE - 9+ yrs
Role - Data Engineer
Location: USA

Got two question on my coding onsite round for google, time was 1 hour:

First :

You have a list of cities and population. 
Write a function that returns a random city name by the probability of its sum of population. 
For example, in the following case, NY population is 14, total is 22. 
You should return NY with the probability of 14/22.

[NY, 9]
[SF, 1.5]
[Atlanta, 3]
[NY, 5]
[Boston, 1]
[SF, 3]

Second:

Write a FriendSuggest function for a social network

Example:
Rob - [A, B, C]
B - [A, C, D, F, Rob]
A - [B, C, D, E, Rob]
C - [A, B, J, Rob]
D - [B, A, F]
G - [H, J]
J - [H, G, K, M]

Expected Output -  [D, E, F, J]

suggestFriend(‘rob’, dict_of_frnd) =  [D, E, F, J]
Comments (15)