All problems
Nonzero AC Count
Problem
Count the nonzero entries of a block excluding the DC term at (0, 0). This is the number of (run, value) symbols a JPEG-style encoder must emit for the alternating-current coefficients.
Hint
Quantization usually drives most AC coefficients to zero.
Test cases
case 1
in: [[[5,1,0],[0,2,0],[0,0,3]]]
expected: 3
case 2
in: [[[1,0],[0,0]]]
expected: 0
case 3
in: [[[0,0],[0,0]]]
expected: 0
case 4
in: [[[1,1],[1,1]]]
expected: 3
Starter codePython
def nonzero_ac_count(block):
# Your code here
pass4 test cases · run your code against them in the editor