You are on page 1of 2

Please use this Google doc during your interview (your interviewer will see

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.

1. Can store all compliments in memory at once


2. Generate purely random compliment
a. eliminate the generated compliment

ToDo: 1. Generate purely random compliment


2. eliminate the generated compliment

Store compliments in a list


Length of the list - L

############
compliments = [A, B, D, E, F]
length = len(compliments)

def random(start, end):


“””
:return A random number between [start, end-1]
“””

def get_random_compliment():
if length == 0:
length = len(compliments)

random_number = random(0, length)


compliment = compliments.pop(random_number)
compliments.append(compliment)
length -= 1

[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)

You might also like