All problems
Zigzag Index
Problem
Return the position (0 to 63) of the cell (row, col) in the standard 8x8 JPEG zigzag order, which starts (0,0), (0,1), (1,0), (2,0), (1,1), (0,2), ... Rows and columns are 0-indexed. Return -1 for out-of-range input.
Hint
The scan alternates between up-right and down-left diagonals.
Test cases
case 1
in: [0,0]
expected: 0
case 2
in: [0,1]
expected: 1
case 3
in: [1,0]
expected: 2
case 4
in: [1,1]
expected: 4
case 5
in: [7,7]
expected: 63
Starter codePython
def zigzag_index(row, col):
# Your code here
pass5 test cases · run your code against them in the editor