All problems
Isotonic Step
Problem
Apply one pool-adjacent-violators pass to values with weights, enforcing a non-decreasing fit. Merge adjacent blocks while the previous block mean exceeds the current one.
Return the expanded fitted values (same length as the input); empty input returns [].
Hint
Whenever a block mean drops below its predecessor, average the two blocks together.
Test cases
case 1
in: [[0.2,0.5,0.4],[1,1,1]]
expected: [0.2,0.45,0.45]
case 2
in: [[0.5,0.4,0.3],[1,1,1]]
expected: [0.39999999999999997,0.39999999999999997,0.39999999999999997]
case 3
in: [[0.1,0.2,0.3],[1,1,1]]
expected: [0.1,0.2,0.3]
case 4
in: [[3,1],[1,3]]
expected: [1.5,1.5]
case 5
in: [[],[]]
expected: []
Starter codePython
def isotonic_step(values, weights):
# Your code here
pass5 test cases · run your code against them in the editor