Find dictionary words on a Boggle grid with multi-letter tiles
In a Boggle-style word game, players trace words through a grid of letter tiles. When the round ends, the game needs the list of every dictionary word that can be traced on the board, to score the players and reveal the words they missed. Implement findBoardWords(board, dictionary).
findBoardWords(board, dictionary) // => string[]
board is a rectangular 2D array of tiles. A tile is a non-empty lowercase string. Most tiles hold one letter, but some hold several, like the classic 'qu' tile. The board can be empty ([]).dictionary is an array of lowercase words. It can contain duplicates and empty strings.'qu' tile gives 'qu', never only 'q' or 'u'.Return every dictionary word that can be traced, once each, sorted alphabetically (the default Array.prototype.sort order).
const board = [
['c', 'a', 't', 's'],
['o', 'r', 'e', 'qu'],
['d', 'e', 'i', 't'],
];
findBoardWords(board, ['cats', 'quest', 'tree', 'tat', 'suit', 'code', 'cats', 'order']);
// => ['cats', 'code', 'quest', 'tree']
'quest': qu → e (left) → s (up-right, diagonal) → t (left).'tat' is not found: the only t touching the a would be used twice.'suit' is not found: there is no u tile, and 'qu' cannot be split.'order' needs two r tiles; the board has one.'cats' appears twice in the dictionary but once in the result.The board can have up to 10 × 10 tiles and the dictionary up to a few thousand words, so avoid work that grows with every word for every path.