Lottery with Add and Pick Operations
Problem statement
Process parallel arrays:
add: append the uniqueusers[i]; returnnull.pick: return the user at zero-based indexchoices[i]in insertion order. The supplied index represents a uniform random draw; picking does not remove the user.
For add, the matching choice and unused user fields may be ignored.
Function
runLottery(operations: String[], users: String[], choices: int[]) → String[]Examples
Example 1
operations = ["add","add","pick","add","pick"]users = ["Ada","Bob","","Cy",""]choices = [0,0,1,0,2]return = ["null","null","Bob","null","Cy"]The injected choices select Bob then Cy.
Constraints
- Every choice for a pick is valid.
- Added users are unique.