public static bool WordExists(char[][] matrix, string target)
if (target.Length > matrix.Length && target.Length > matrix[0].Length)
for (int row = 0; row < matrix.Length; row++)
for (int col = 0; col < matrix[row].Length; col++)
char letter = matrix[row][col];
if (letter == target[tarIdx])
if (tarIdx == target.Length)
for (int col = 0; col < matrix[0].Length; col++)
for (int row = 0; row < matrix.Length; row++)
char letter = matrix[row][col];
if (letter == target[tarIdx])
if (tarIdx == target.Length)
public static void Main()
Console.WriteLine(WordExists(new char[][]{new char[]{'F', 'A', 'C', 'I'}, new char[]{'O', 'B', 'Q', 'P'}, new char[]{'A', 'N', 'O', 'B'}, new char[]{'M', 'A', 'S', 'S'}}, "ACI"));