0

Hello!

I'm trying to find the longest sequence of equal elements in a matrix M x N. I use two nested for-loops to search into the rows and compare the cells - same thing for the columns. When two adjacent elements are equal, I increment a counter. If the counter is greater than the previous one, I save the new counter value and the current element.

Now I should search in the diagonal directions. How can I do? If *i* and *j* are the indexes of a cell, the main diagonal (from left to right) has *i == j*. But for the secondary diagonals (from left to right and from right to left)? I also have a problem to reach the border of the matrix to avoid the IndexOutOfRangeException... Any help is appreciated.

*Edited 1 Year Ago by Rik30*