Diagonal matrix traversal, implemented as an iterator class.
Asked in the Round 1 stage. Implement diagonal zigzag traversal for a rectangular matrix. The grading function must return the values produced by the iterator as a list.
diagonal_iterator(matrix) receives a list of equal-length row lists and returns a list in diagonal zigzag order. Start at the top-left cell, alternate upward-right and downward-left directions, and stop after every cell is visited.
Example: [[1, 2, 3], [4, 5, 6]] returns [1, 2, 4, 5, 3, 6].
Constraints: The matrix may be empty, has rectangular rows, and contains integers.
def diagonal_iterator(matrix):