Classic example
Input
board = [['o','a','a','n'],['e','t','a','e'],['i','h','k','r'],['i','f','l','v']]; words = ['oath','pea','eat','rain']
Output
['eat', 'oath']
'oath' and 'eat' can be constructed; 'pea' and 'rain' cannot. Output is sorted.
Full lesson preview
Search a grid for multiple given words using backtracking; return which words exist.
Problem statement
Task
Examples
Input
board = [['o','a','a','n'],['e','t','a','e'],['i','h','k','r'],['i','f','l','v']]; words = ['oath','pea','eat','rain']
Output
['eat', 'oath']
'oath' and 'eat' can be constructed; 'pea' and 'rain' cannot. Output is sorted.
Input format
Output format
Constraints
Samples
Input
board = [['a','b'],['c','d']]; words = ['abcb']
Output
[]
Although 'abc' is adjacent, 'abcb' would require revisiting a cell which isn't allowed.