All problems
Rejection Sampling Pick
Problem
Return the index of the first candidate whose score is at least threshold, or -1 when no candidate qualifies. Comparison is inclusive (>=).
The signature is rejection_sampling_pick(scores, threshold).
Hint
Rejection sampling keeps generating until a sample passes the threshold.
Test cases
case 1
in: [[0.1,0.5,0.9],0.6]
expected: 2
case 2
in: [[0.1,0.5,0.9],0.2]
expected: 1
case 3
in: [[0.1,0.5,0.9],0.95]
expected: -1
case 4
in: [[1],0.5]
expected: 0
case 5
in: [[0.3,0.3],0.3]
expected: 0
Starter codePython
def rejection_sampling_pick(scores, threshold):
# Your code here
pass5 test cases · run your code against them in the editor