Capital One Interview Question

One matrix question from leetcode