Valtech Interview Question

traverse the matrix