Skip to content
DeepForgeby svx
All problems
MediumInformation Theoryinfo-187

Water-Filling Level Update

Problem

Perform one water-filling update. Given noise variances, the current water level and the target total power, count the active channels with n_i < level, compute the used power sum(max(0, level - n_i)), and return level + (target_power - used) / active. Return the level unchanged when no channel is active.

Hint

If the used power already matches the target, the level does not move.

Test cases

case 1
in: [[1,1],2,2]
expected: 2
case 2
in: [[1,1],0,4]
expected: 0
case 3
in: [[1,3],2,4]
expected: 5
case 4
in: [[1,3],0.5,1]
expected: 0.5
Starter codePython
def water_filling_update(noise_vars, level, target_power):
    # Your code here
    pass

4 test cases · run your code against them in the editor