All problems
Object Pool Checkout and Checkin
Problem
Simulate an object pool with fixed capacity.
operations contains "checkout" (lend the smallest free object id, or -1 when none are free), "checkin" (values[i] is the returned object id, recording True or False), "available" (record the number of free objects), or "in_use" (record the number of lent objects).
Return the list of recorded results.
Hint
Checking in an id that is not currently lent must be rejected.
Test cases
case 1
in: [3,["checkout","checkout","checkin","checkout","available","in_use"],[0,0,0,0,0,0]]
expected: [0,1,true,0,1,2]
case 2
in: [1,["checkout","checkout","available"],[0,0,0]]
expected: [0,-1,0]
case 3
in: [2,["checkin","available"],[5,0]]
expected: [false,2]
case 4
in: [2,["checkout","checkin","checkin","available"],[0,0,0,0]]
expected: [0,true,false,2]
Starter codePython
def pool_ops(capacity, operations, values):
# Your code here
pass4 test cases · run your code against them in the editor