Problem
You are given an m x n grid of letters board and a list of words. Return every word from the list that can be spelled on the board.
A word is spelled by starting on any cell and moving to a horizontally or vertically adjacent cell for each next letter. The same cell may not be used twice within one word. Return each found word once, in any order.
Example 1
board = [["o", "a", "a", "n"],
Example 2
["e", "t", "a", "e"],
Example 3
["i", "h", "k", "r"],
Example 4
["i", "f", "l", "v"]]
Example 5
- Input
- words = ["oath", "pea", "eat", "rain"]
- Output
- ["eat", "oath"]
Example 6
- Input
- board = [["a", "b"], ["c", "d"]], words = ["abcb"]
- Output
- []
Constraints
m == board.length, n == board[i].length1 <= m, n <= 12board[i][j] is a lowercase English letter.1 <= words.length <= 3 * 10^41 <= words[i].length <= 10All words in words are unique.