#K70267. Longest Contiguous Sequence in Binary Matrix
Longest Contiguous Sequence in Binary Matrix
Longest Contiguous Sequence in Binary Matrix
You are given a binary matrix \(M\) of dimensions \(n \times m\). Your task is to determine the length of the longest contiguous sequence of 1's that appears either in any row or in any column of the matrix.
Input: The matrix is provided via standard input.
Output: Output a single integer denoting the length of the longest contiguous sequence of 1's found.
Example:
For a \(4 \times 5\) matrix shown below:
1 0 1 1 0
1 1 1 0 0
0 0 0 1 1
1 1 1 1 0
The longest contiguous sequence is 4 (in the last row).
inputFormat
The first line of input contains two integers \(n\) and \(m\) representing the number of rows and columns in the matrix respectively. The next \(n\) lines each contain \(m\) integers (each either 0 or 1) separated by spaces, representing the rows of the matrix.
outputFormat
Output a single integer to standard output representing the length of the longest contiguous sequence of 1's along any row or column of the matrix.
## sample4 5
1 0 1 1 0
1 1 1 0 0
0 0 0 1 1
1 1 1 1 0
4