BackhardBacktracking

Lexical Grid Explorer Solution

Problem Statement

Given a 2D grid of characters and a target string, determine if the target string can be constructed from adjacent characters in the grid, where each character in the grid can only be used once in the construction of the target string.

Example 1
Input
{"grid":[["a","b","c"],["d","e","f"],["g","h","i"]],"target":"beg"}
Output
true

Explanation: The target string 'beg' can be constructed from the grid by moving from 'b' to 'e' to 'g'.

Example 2
Input
{"grid":[["a","b","c"],["d","e","f"],["g","h","i"]],"target":"xyz"}
Output
false

Explanation: The target string 'xyz' cannot be constructed from the grid as none of the characters 'x', 'y', or 'z' are present.

Constraints

  • The grid will contain only lowercase English letters.
  • The target string will contain only lowercase English letters.
  • The grid will be at most 20x20 characters in size.
  • The target string will be at most 20 characters in length.
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