All problems
Rice Remainder Length
Problem
Encode a non-negative integer n with a Rice code of parameter k >= 1. The quotient q = n >> k is written in unary using q + 1 bits and the k-bit remainder is appended, so the total codeword length is q + 1 + k. Return that length.
Hint
The unary part grows with the quotient while the binary remainder is always k bits.
Test cases
case 1
in: [0,3]
expected: 4
case 2
in: [8,3]
expected: 5
case 3
in: [100,3]
expected: 16
case 4
in: [5,1]
expected: 4
Starter codePython
def rice_remainder_length(n, k):
# Your code here
pass4 test cases · run your code against them in the editor