All problems
First-Fit Pick
Problem
Pick the first free block that fits a request.
free_blocks is the list of free block sizes in address order and request is the wanted size. First fit returns the index of the first block whose size is at least the request.
Return that index, or -1 when no block is large enough.
Hint
Scan from the beginning and stop at the first sufficiently large block.
Test cases
case 1
in: [[5,2,8,3],4]
expected: 0
case 2
in: [[1,2,3],3]
expected: 2
case 3
in: [[1,2],5]
expected: -1
case 4
in: [[],1]
expected: -1
Starter codePython
def first_fit_pick(free_blocks, request):
# Your code here
pass4 test cases · run your code against them in the editor