Search Word In Matrix problem states that “Given a 2D matrix filled with some characters. Check whether the word exist in the matrix or not”. All movements right, left, up, down and diagonally are possible. For example The below given matrix filled with some characters find how many times “home” occurs. The word “home” in given matrix occurs two times. Print 0 if matrix does not contain pattern (word).

Search Word In Matrix

How to Search Word In Matrix

  • If any index (i,j) of given matrix is equal to the first letter of string to be searched.
  • Search for next match.
  • Else Backtrack.

Test Case:


Note: Submit your article at

Related Contents to follow