Microsoft interview question

leetcode question about string and matrix