Remitly Phone Interview - Build datastructure and add/pick tasks with weight

Question: You are given a task to build a data structure behind a set of functions to add tasks each with a weight associated with it and a function to pick a task. Write a class to manage these set of tasks with the following features:

  1. ability to manage tasks to be added from this over time add(Task a, int weight)
  2. function pickTask() to choose a task based on the weight associated with it

For example, let’s say we have two tasks Task-A with weight 6 and Task-B with weight 4. If I call the pickTask() function 100 times I should get on average Task-A served 60 times and Task-B served 40 times.

Comments (4)