Back to the 100
Problem 060Binary Search
Medium

Random Pick with Weight

060

Given weights and random target values in [1,totalWeight], return the picked index for each target using weighted prefix ranges.

EXAMPLES

Example 1
Input
{
  "w": [
    1,
    3
  ],
  "targets": [
    1,
    2,
    4
  ]
}

Output
[
  0,
  1,
  1
]

FUNCTION SHAPE

w: intArraytargets: intArrayintArray
00:00
2 local tests readyRun with ⌘/Ctrl + Enter. Your code stays in this browser.

Runs solve(...) locally in a browser worker. SWE Playbook does not submit your code. Only run code you trust; Python code may access the network.