Deloitte interview question

Matrix traversal question, had seen a variation on Leetcode