You are given:
board
with
m
rows and
n
columns.
words
(a dictionary).
A word can be formed by starting from any cell and moving to adjacent cells (up, down, left, right). Each cell may be used at most once in forming a single word.
Return all distinct words from words that can be formed in the grid.
board
:
m x n
array of lowercase letters.
words
: list of lowercase strings.
1 <= m, n <= 12
1 <= len(words) <= 3 * 10^4
1 <= len(word) <= 10
a-z
.