All problems
Random Pick Index (Seeded)
Problem
Pick a uniformly random index of target in a list using a seeded generator.
Collect the positions where nums equals target, then use random.Random(seed).randrange to choose one so the result is reproducible. Return -1 when target does not appear.
Return the chosen index.
Hint
Seeding a fresh Random instance makes the pick fully deterministic.
Test cases
case 1
in: [[1,2,3,3,3],3,0]
expected: 3
case 2
in: [[1,2,3,3,3],3,1]
expected: 2
case 3
in: [[],5,0]
expected: -1
case 4
in: [[5,5],5,42]
expected: 0
Starter codePython
def random_pick_index(nums, target, seed):
# Your code here
pass4 test cases · run your code against them in the editor