Find the longest line in 2D (MxM) array (vertical, horizontal, or diagonal)
In worst case (array that has only 1, no 0) you are doing M operations for each cell in MxM for a total of M^3 operations. You can reduce it to M^2 if you remember the results for previous row (for vertical, LD, RD) and current(horizontal). If the cell is 1 increment the counters, otherwise reset them to zero.