Given a grid of lowercase letters and a dictionary words, return every distinct word that can be formed by walking horizontally or vertically adjacent cells. A board cell may be used at most once per word.
To keep judge output deterministic, return the found words sorted in ascending lexicographic order.
Input / output
board: string[], words: string[]string[] sorted ascending, with no duplicatesExamples
board = ["oaan","etae","ihkr","iflv"], words = ["oath","pea","eat","rain"] returns ["eat","oath"].board = ["ab","cd"], words = ["abcb","ab","abc","abd"] returns ["ab","abd"].board = ["a"], words = ["a","aa","b"] returns ["a"].Constraints
1 <= board.length, board[i].length <= 121 <= words.length <= 30001 <= words[i].length <= 10words may contain duplicates, but the output should list each found word onceTarget complexity
Hints
Follow-up How would you remove found words from the trie aggressively so later DFS branches prune even earlier?