board is a grid of letters (a list of equal-length strings). A word can be traced by walking between neighbouring cells (up, down, left, right), using each cell at most once per word. Return the different words from words that can be traced, sorted.
For board = ["oaan", "etae", "ihkr", "iflv"] and words = ["oath", "pea", "eat", "rain"] the answer is ["eat", "oath"].
The starter code runs a separate board search for every word. It is correct but too slow for many words.
Example 1
Input:
find_words(['oaan', 'etae', 'ihkr', 'iflv'], ['oath', 'pea', 'eat', 'rain'])
Output:
['eat', 'oath']
Example 2
Input:
find_words(['ab', 'cd'], ['abcb'])
Output:
[]
0 <= rows, cols <= 80 <= len(words) <= 3000No results yet
Run your code to check it against the examples, or submit to run every test.