Dsa
Backtracking
Warm-up
Matrix Word Search
Given a 2D grid of characters and a target word, determine if the word can be constructed from adjacent cells (horizontally or vertically) in the grid. Each cell can be used only once per word.
Input Format:
- The first line contains two integers, m and n (1 ≤ m, n ≤ 5).
- The next m lines contain n characters each, representing the grid.
- The last line contains the target word.
Output Format:
- Print 'Yes' if the word can be formed or 'No' otherwise.
Example:
Input:
2 2
ab
cd
to
Output:
No
Key concepts
backtrackingmatrix searchstring search
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now