You will be given a 2-dimensional grid of letters and a length.
Write a method to count the total number of distinct paths of consecutive letters of the given length, starting at 'A'.
Paths can step from one square in the grid to any adjacent square (horizontally, vertically, or
diagonally).
For example, in the following grid, there are 7 paths of consecutive letters from 'A' to 'C':
{ "ABC",
"CBZ",
"CZC",
"BZZ",
"ZAA" }
A B C A . C A B . A . . A . . A . . . . .
. . . . B . C . . C B . . B . . B . . . .
. . . . . . . . . . . . C . . . . C C . .
. . . . . . . . . . . . . . . . . . B . .
. . . . . . . . . . . . . . . . . . . A .
(spaces are for clarity only)
so, for this grid and a length of 3, your method should return 7.
If there are more than 1,000,000,000 paths, your method should return 1,000,000,000.
|