Algorithm to detect more than one sequence of 4 same letters horizontally, vertically or diagonally : I have been assigned a task to write an algorithm to detect if a given array of strings contains more than one sequence of 4 repeated letters horizontally, vertically or diagonally. They also asked me the most efficient way to do it.

An input example would be something like this:

`String[] input = {"ATGCGA","CAGTGC","TTATGT","AGAAGG","CCCCTA","TCACTG"};`

but you guys can see it more clearly like a table here:

A T G C G A

C A G T G C

T T A T G T

A G A A G G

C C C C T A

T C A C T G

This array contains 3 sequences with a repeated letter:

AAAA is found diagonally
CCCC is found horizontally
GGGG is found vertically

So, since there are more than 1 sequence found in this input example, the output should be true.


I have an idea to solve this problem but my major issue is handling the diagonals, especially using an efficient way to do it since they expect to use this function in a high concurrency environment.

I would be grateful for any help provided. It's ok if someone can't write the code, but at least some ideas to get the right approach to solve this problem.

I am thankful already!