Word Search II
Detailed guide and Python implementation for the 'Word Search II' problem.
Problem Statement
Given an m x n board of characters and a list of strings words, return all words on the board.
Each word must be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically neighboring. The same letter cell may not be used more than once in a word.
Write a function findWords(board: List[List[str]], words: List[str]) -> List[str].
- •m == len(board)
- •n == len(board[i])
- •1 <= m, n <= 12
- •board[i][j] is a lowercase English letter
- •1 <= len(words) <= 3 * 10^4
- •1 <= len(words[i]) <= 10
- •words consist of lowercase English letters
- •All the strings in words are unique
Examples
board = [["o","a","a","n"],["e","t","a","e"],["i","h","k","r"],["i","f","l","v"]], words = ["oath","pea","eat","rain"]
["oath","eat"]
The words "oath" and "eat" can be found on the board. "pea" and "rain" cannot.
board = [["a","b"],["c","d"]], words = ["abcb"]
[]
The word "abcb" requires using the 'b' cell twice, which is invalid.
Need a Hint?
Edge Cases to Watch
- Empty input structures
- Single element inputs
- Large numerical bounds
Ready to Solve?
Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.
Recommended Python Resources
Expand your knowledge with related interactive tutorials, cheat sheets, and code comparisons.
Python Loops
Learn how to use Python loops to iterate over data. Master for loops, while loops, break, continue, and loop best practices with interactive examples.
How to Sort a List in Python
Learn how to sort a list in Python using the sort() method and the sorted() function. Discover custom key sorting and reverse order examples.
Python String Methods
A complete reference guide for Python string manipulation. Master formatting, searching, splitting, replacing, and checking string properties.
Python vs JavaScript: Which Programming Language is Best?
A comprehensive comparison between Python and JavaScript. Explore syntax differences, performance, use cases (backend vs frontend), and coding examples.