BackmediumBacktracking

Lexical Grid Exploration Solution

Problem Statement

Given a 2D grid of letters and a target string, find all occurrences of the target string in the grid. The target string can be found horizontally, vertically, or diagonally in the grid, in a contiguous path.

Example 1
Input
{"grid":[["A","B","C"],["D","E","F"],["G","H","I"]],"target":"AEH"}
Output
[]

Explanation: The target string 'AEH' cannot be found in the grid.

Example 2
Input
{"grid":[["X","Y","Z"],["W","X","Y"],["V","W","X"]],"target":"XYZ"}
Output
[]

Explanation: The target string 'XYZ' cannot be found in the grid.

Example 3
Input
{"grid":[["A","B","C"],["D","E","F"],["G","H","I"]],"target":"JKL"}
Output
[]

Explanation: The target string 'JKL' cannot be found in the grid.

Constraints

  • The grid will contain at least one row and one column.
  • The target string will be between 1 and 10 characters long.
  • All characters in the grid and target string will be uppercase letters.
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