FastPrepLottery with Add and Pick Operations

Lottery with Add and Pick Operations

Bloomberg LP logoBloomberg LP● EasyNEW GRADONSITE INTERVIEW
Learn

Problem statement

Process parallel arrays:

  • add: append the unique users[i]; return null.
  • pick: return the user at zero-based index choices[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.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public String[] runLottery(String[] operations, String[] users, int[] choices) {
  // Write your code here.
}
operations["add","add","pick","add","pick"]
users["Ada","Bob","","Cy",""]
choices[0,0,1,0,2]
expected["null", "null", "Bob", "null", "Cy"]
Checking account…