Amazon interview question

Word search problem on leetcode