Professional Documents
Culture Documents
Google Interview Document
Google Interview Document
what you write here). To free your hands for typing, we recommend using a
headset or speakerphone.
Right now I’m making an app that displays compliments. When you push a button
it shows a compliment. While I have the rest of the framework available, I
don’t have the ability to get a random compliment. Given a collection of
compliments, return a random compliment.
############
compliments = [A, B, D, E, F]
length = len(compliments)
def get_random_compliment():
if length == 0:
length = len(compliments)
[A, B, D, E, F, A, D, E, F, B]
L = 10
R = 6
L = 9
R = 8
L=8
Our users have found certain compliments very lovely and others not so great.
So I ask you hey if we can implement a rating system. We’ve come down to two
potential systems, the first is where 0 is the baseline and 1 shows up twice
as often as 0. The second one is we want to extend the rating from 0 to
infinity where compliments rated 1 show up twice as often as 0. Compliments
rated 2 show up 3 times often as 0 and so on and so forth
a b c
0 1 0
1/4 1/2 1/
4
a b c d
0 1 0 2
1/ 2/7 1/7 3/
7 7
Queue -
Node:
compliment: str
weight: int
(d,2)
(b,1) (a,0)
(c,-1)