Trains the technique from
LeetCode 212Word Search IIThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
An engraved plate holds one lowercase letter per cell: board[r][c] is the letter in row r, column c. You are also handed a catalogue of distinct words.
A word is traceable when you can put a stylus on some cell and then move it one cell at a time, up, down, left or right, so that the letters visited spell the word from start to finish. While tracing a single word the stylus may never revisit a cell it has already used. Each word is traced from scratch, so a cell used while tracing one word is free again for the next one.
Return every word of the catalogue that is traceable on this plate. The returned words may be in any order, and each traceable word appears once.
Example 1
`sea` runs across the top row. `sto` runs down the first column. `art` runs down the last column. `top` starts at the `t` in the middle of the left column, drops to `o`, then steps right to `p`. `set` cannot be traced because no `t` touches the `e`, and `extra` runs out of neighbours after `ext`.
Example 2
`aab` starts at the bottom-left `a`, steps up to the top-left `a`, then right to `b`. `aba` starts at the top-left `a`, steps right to `b`, then down to the bottom-right `a`. The plate holds a single `b`, so `bb` has nowhere to go after its first letter.
Example 3
The plate holds four cells of `s`, so a stylus can spell two, three or four of them by snaking through distinct cells. `sssss` would need a fifth cell, and no cell may be reused inside one word.
The values you return may be in any order.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def find_words(board: list[list[str]], words: list[str]) -> list[str]:public List<String> findWords(char[][] board, String[] words)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.