A word game in your app shows a grid of letters. A word can be spelled by starting on any cell and moving to a neighboring cell (up, down, left, or right) for each next letter. A cell can't be used twice in the same word.
Write findWords(board, words) that returns every word from words that can be spelled on board, each once, sorted alphabetically. board is an array of equal-length strings, one per row.
Input: board = ["cat","ore","dog"], words = ["cat","cord","dog","toe","rat"] Output: ["cat","dog","rat"]
rat goes from the middle r up to a, then right to t. cord fails because d is not next to r.
Input: board = ["ab","cd"], words = ["abdc","abcd"] Output: ["abdc"]
a → b → d → c follows neighbors; in abcd, b and c are not neighbors.
1 <= rows, columns <= 121 <= words.length <= 3 * 10^41 <= words[i].length <= 10Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #371 Spell Words on a Letter Grid. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.