BackhardBacktracking

Grid Lexicon Verification Solution

Problem Statement

Given a 2D grid of characters and a list of words, determine if each word can be formed by traversing the grid, with the constraint that each cell can only be used once per word, and all movements are either horizontal or vertical.

Example 1
Input
{"grid":[["A","B","C"],["D","E","F"],["G","H","I"]],"words":["AB","DE","GH"]}
Output
[true,true,true]

Explanation: Each word can be found in the grid by moving either horizontally or vertically without reusing any cells within the same word.

Example 2
Input
{"grid":[["J","K","L"],["M","N","O"],["P","Q","R"]],"words":["JK","MN","PQR"]}
Output
[true,true,true]

Explanation: All the provided words can be formed within the grid, adhering to the rule of not reusing cells and only moving horizontally or vertically.

Constraints

  • The grid size can be up to 10x10.
  • The number of words to find can be up to 10.
  • Each word length can be up to 5 characters.
  • Only English alphabets are used in the grid.
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free