3
\$\begingroup\$

BackStory

Given a square matrix of alphabets which contain English letters in arbitrary manner. While searching a word in it, you can go left to right horizontally, vertically downwards or diagonally towards left (both upwards and downwards).

You have to find the number of matches of a given word in the matrix.

For example, In the given square matrix {A#A#K,A#S#K,A#K#K},enter image description here

The word "ASK" is matched four times in the input matrix. So the output will be 4.

Input Format

You will be given two-dimensional string array and a string(Word to be searched) as arguments.

Output Format

You need to return the Number of occurrences of the word in the matrix {an integer}.

Sample Test Case1

Sample Input

2
2
A S
S T

AS

Sample Output

2

Sample Test Case 2

Sample Input
5
5
E D E E E
D I S K E
E S E E E
E C E E E
E E E E E

DISK

Sample Output

1

Explanation:

In this example, "DISK" is matched only one time in the input matrix. So the output will be 1.

Winning

Shortest code in bytes wins.

\$\endgroup\$
  • \$\begingroup\$ Closely related, but not quite a duplicate. \$\endgroup\$ – AdmBorkBork Jul 31 '17 at 15:03
  • \$\begingroup\$ You will be given a function which contains -> what does that mean? Would getting input in a different format be acceptable? \$\endgroup\$ – Stephen Jul 31 '17 at 15:03
  • \$\begingroup\$ Yep... @Arnauld \$\endgroup\$ – Mickey Jack Jul 31 '17 at 15:05
  • \$\begingroup\$ The input format is specified clearly.@StepHen \$\endgroup\$ – Mickey Jack Jul 31 '17 at 15:09
  • 2
    \$\begingroup\$ This appears to be copied from elsewhere, without attribution. I'll put this on hold until you add one. \$\endgroup\$ – Dennis Jul 31 '17 at 15:32

Browse other questions tagged or ask your own question.