All problems
Replica Autoscaling
Problem
Compute the desired replica count from queue load: desired = ceil(current * queue_length / target_queue), clamped to [min_replicas, max_replicas].
The signature is autoscale_replicas(current, queue_length, target_queue, max_replicas, min_replicas=1). Return an integer.
Hint
Clamping avoids both thrashing below one replica and unbounded scale-out.
Test cases
case 1
in: [2,100,50,10]
expected: 4
case 2
in: [2,0,50,10]
expected: 1
case 3
in: [5,200,50,6]
expected: 6
case 4
in: [1,50,50,4]
expected: 1
Starter codePython
import math
def autoscale_replicas(current, queue_length, target_queue, max_replicas, min_replicas=1):
# Your code here
pass4 test cases · run your code against them in the editor