Problem Statement |
| | WordFind is one of the simplest and funnest puzzles to play by oneself. It is played on a rectangular board where each cell contains a lowercase letter ('a'-'z').
A word can be found horizontally on the board if there is a path of consecutive cells in the same row of the board that spells out the word either left-to-right or right-to-left. Similarly, a word can be found vertically on the board if there is a path of consecutive cells in the same column that spells out the word either top-to-bottom or bottom-to-top. See examples 0 and 1 for clarification.
A word can be perfectly found on the board if it can be found both vertically and horizontally. You are given a String[] board representing the board, and a String[] words containing a list of words. Return the number of words in the given list that can be perfectly found on the board. |
| |
Definition |
| | | Class: | WordFindPuzzle | | Method: | solveWordFindPuzzle | | Parameters: | String[], String[] | | Returns: | int | | Method signature: | int solveWordFindPuzzle(String[] words, String[] board) | | (be sure your method is public) |
|
| |
|
| |
Constraints |
| - | words will contain between 0 and 30 elements, inclusive. |
| - | Each element of words will contain between 1 and 30 characters, inclusive. |
| - | All elements of words will be distinct. |
| - | board will contain between 1 and 30 elements, inclusive. |
| - | Each element of board will contain between 1 and 30 characters, inclusive. |
| - | All elements of board will be of the same length. |
| - | All elements of words will contain only lowercase letters ('a'-'z'). |
| - | All elements of board will contain only lowercase letters ('a'-'z'). |
| |
Examples |
| 0) | |
| | |
| 1) | |
| | {"jay"} | {"yaj",
"tea",
"hey"} |
| Returns: 1 | |
|
| 2) | |
| | {"aaa", "aab", "aac"} | {"aaa",
"aba",
"caa"} |
| Returns: 2 | | "aaa" and "aac" can be perfectly found on this board. |
|
|
| 3) | |
| | {"park", "kim", "lee", "choi"} | {"lxamal",
"alkime",
"parkpe",
"lyaeel",
"aypepl"} |
| Returns: 3 | | Four common Korean last names are given as words. 3 most common last names, namely "kim", "lee", and "park", can be found on the board. |
|
|
| 4) | |
| | {"ava", "abigail", "cailyn", "madeline", "isabella",
"emma", "caitlyn", "olivia", "chloe", "brianna"} | {"vase",
"amme",
"vmal",
"aeve"} |
| Returns: 1 | | 10 female names are given as words. "emma" is the only one perfectly found on the given board. |
|
|
| 5) | |
| | {"alex", "bob", "chris", "david",
"edward", "frank", "gabriel"} | {"gabrielxl",
"hfodavide",
"arbibobri",
"daavxelar",
"enlalexwb",
"nkedwarda",
"cbxyzlaeg"} |
| Returns: 5 | | 7 male names are given this time. You can perfectly find all but "chris" and "frank" on the board. |
|
|