Dsa
Backtracking
Hard
Word Search Puzzle
You are given a 2D grid of characters representing a word search puzzle and a list of words. Your task is to find all words from the list that can be formed by sequentially adjacent characters, where adjacent characters can be horizontally or vertically neighboring. Each letter can only be used once in the word. Print the words found in the grid.
Input:
- The first line contains two integers n and m (1 ≤ n, m ≤ 15), the dimensions of the grid.
- The next n lines contain m uppercase letters (A-Z) representing the grid.
- The last line contains an integer k (1 ≤ k ≤ 50), the number of words.
- The next k lines each contain an uppercase word.
Output:
- Print each word found in the grid, one per line.
Example:
Input:
3 4
ABCD
EFGH
IJKL
3
ABCD
EFG
XYZ
Output:
ABCD
EFG
Key concepts
backtrackingstringssearch
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