Implement addTicket, removeTicket and getRandom with weighted random selection.
Unlock detailed company stats for this questionUpgrade
A fair is organized: based on some good action a member is given 1 ticket, and based on some bad action a ticket is taken from the member. Implement three methods: addTicket(memberId), removeTicket(memberId) and getRandom(). getRandom() picks a member with probability weighted by the number of tickets the member has (a member with 5 tickets is more likely than one with 1 ticket). All three functions should be O(1) average case.
A variation of Insert Delete GetRandom O(1) (LeetCode 380).
Format · LinkedIn phone screen.
Community answers
No answers contributed by the community yet.
Related questions
Implement Rand10() using Rand7() with rejection sampling.Related courses

Course

Course
Course
