Word Search
Problem Statement
You are given a grid of letters, board, and a string, word. Return true if the word can be spelled by a path through the grid.
Each letter comes from one cell. Each step moves to a neighbouring cell: up, down, left or right (no diagonals). A path may not use the same cell twice. Letters are case-sensitive, so a and A are different.
board, an m × n grid of letters, and word, a string.
true if the word can be spelled this way, otherwise false.
The path is A (0,0), B (0,1), C (0,2), C (1,2), E (2,2), D (2,1). Each cell is used once.
The path is S (1,3), E (2,3), E (2,2).
The second B would have to reuse the only B on the board, at (0,1).
- • 1 ≤ m, n ≤ 6, where m is the number of rows and n is the number of columns.
- • 1 ≤ word.length ≤ 15
- • The board and the word use only lowercase and uppercase English letters.
- • Follow-up: how could search pruning make the search faster on a bigger board?
Pattern Recognition Clues
Recognising these key signals in the problem description immediately identifies the pattern:
Approach Complexity Ladder
For each start, search with a set of used cells that every call copies
One board: mark a used cell with #, try its neighbours, then put the letter back
Try every cell as the starting letter. For each start, begin with an empty set of used cells. Every call copies that set and adds its own cell before it looks at the neighbours. The copying is the expensive part.
Recognition rule for this sub-pattern:
Unlock Complete Visual Walkthrough & Optimal C++
The interactive animated dry-run player, optimized C++ implementation, state invariant derivations, and edge-case breakdown for this question are part of Brute2Best Pro. The anchor question of every sub-pattern is completely free.
First anchor question per pattern, Part 1 LLD & Module 1 C++ basics are 100% Free forever.
How this concept connects to System Design & C++ Systems
Top engineering interviews test whether you understand how algorithms like Backtracking translate into production architectures and low-level memory mechanics.
Foundations: Object-Oriented Principles in C++23
Class invariants, pure virtual interfaces, and RAII smart pointers.
Food Delivery System (Zomato Architecture)
Real-world machine coding application of algorithms and design patterns.
Pointers vs References Deep Dive
Pointer arithmetic and memory layout under the hood.
Virtual Method Table (vtable) & Memory Layout
Polymorphism, vptr overhead, and multiple inheritance in memory.