Amazon Interview Question

Word search problem on leetcode