Word Search Ii

hard
1. Given an m x n board of characters and a list of strings words, return all words present on the board.
2. Word must be made from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically neighboring. The same letter cell may not be used more than once in a word.

You can return word's in any order.

Input Format

n m str1 str2 ... n string's each of length m len count of words str1 str2 ... len number of string's.

Output Format

Output is managed for you

Constraints

1. 1 <= m, n <= 12
2. 1 <= words.length <= 3 * 10^4
3. 1 <= words[i].length <= 10
4. words[i] consists of lowercase English letters.
5. All the strings of words are unique.

Notice

Try First, Check Solution later

1. You should first read the question and watch the question video.
2. Think of a solution approach, then try and submit the question on editor tab.
3. We strongly advise you to watch the solution video for prescribed approach.

Example

Input
4
4
oaan
etae
ihkr
iflv
5
oath
pea
eat
eatat
rain
Output
[eat, oath]
Previous
Design Add And Search Words Data Structure
Next
Map Sum Pairs

Related Questions