Count the word from matrix

3

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.

Mickey Jack

Posted 2017-07-31T14:57:54.197

Reputation: 157

Question was closed 2017-07-31T15:32:07.053

Closely related, but not quite a duplicate. – AdmBorkBork – 2017-07-31T15:03:15.743

You will be given a function which contains -> what does that mean? Would getting input in a different format be acceptable? – Stephen – 2017-07-31T15:03:52.017

Yep... @Arnauld – Mickey Jack – 2017-07-31T15:05:59.570

The input format is specified clearly.@StepHen – Mickey Jack – 2017-07-31T15:09:04.657

If KSID is in the matrix, does it count as an occurrence of DISK? – Erik the Outgolfer – 2017-07-31T15:09:28.973

No .@EriktheOutgolfer........... – Mickey Jack – 2017-07-31T15:09:55.220

2This appears to be copied from elsewhere, without attribution. I'll put this on hold until you add one. – Dennis – 2017-07-31T15:32:07.053

No answers