← Back to companies
[ OK ] Loaded —
[ INFO ]
$ cd
$ ls -lt
01
02
03
04
05
$ ls -lt
01
02
03
04
05
user@intervues:~/$
Design a lottery system that supports the following operations in O(1) average time:
add(ticketId) – Adds a ticket with the given ID to the pool. If the ID already exists, return false; otherwise return true.remove(ticketId) – Removes the ticket with the given ID from the pool. If the ID does not exist, return false; otherwise return true.draw() – Returns a uniformly random ticket ID from the current pool. If the pool is empty, return -1.The system must handle up to 10^5 operations efficiently.