Magic Leap interview question

A leetcode question about matrix and dfs.