Skip to main content
All Questions

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 courses

Course

Software Engineering Interview Prep

Land your dream software engineering role at Google, Amazon, Microsoft, Meta, Apple, and other top companies. Learn from mock interviews, frameworks, and advice from senior candidates—practice data structures, algorithms, system design, people management, behavioral interviews, and more.

Course

System Design Interviews

Learn how to answer the latest system design questions across product, infrastructure, and AI domains. Features in-depth video examples, written breakdowns, and helpful reference patterns. Watch senior engineers and managers answer these questions in mock interview videos.