Word Search II
Problem statement
Given a rectangular board of lowercase letters and a list of lowercase words, return every distinct input word that can be formed by a path through horizontally or vertically adjacent cells.
A cell may be used at most once within one word. Return matching words in the order of their first appearance in words.
Function
findWords(board: String[], words: String[]) → String[]Examples
Example 1
board = ["oaan","etae","ihkr","iflv"]words = ["oath","pea","eat","rain"]return = ["oath","eat"]Both returned words have valid adjacent-cell paths.
Example 2
board = ["ab","cd"]words = ["ab","abc","abd","ab"]return = ["ab","abd"]Duplicate input words are returned once, and diagonal movement is not allowed.
Constraints
1 <= board.length, board[i].length <= 12.1 <= words.length <= 30000.1 <= words[i].length <= 10.- Rows have equal length and all characters are lowercase English letters.