#K85077. Longest Possible Street
Longest Possible Street
Longest Possible Street
You are given a city map represented as an n x m grid. Each cell of the grid is either an empty cell denoted by E
or a building denoted by B
. A street is defined as a contiguous sequence of empty cells which is either perfectly horizontal or perfectly vertical. Your task is to determine the length of the longest possible street.
More formally:
Let the grid be denoted by \(A\) where \(A_{i,j}\) is either \(E\) or \(B\). You need to find the maximum number \(k\) such that there exists a sequence of \(k\) consecutive positions in a row or a column, all of which are \(E\).
Example:
Input: 5 5 E E E B E E B E E E E E E E E E B E E E E E E B E</p>Output: 5
inputFormat
The input is read from standard input (stdin) and is structured as follows:
- The first line contains two integers (n) and (m) representing the number of rows and columns of the grid respectively.
- The following (n) lines each contain (m) characters separated by spaces. Each character is either 'E' (representing an empty cell) or 'B' (representing a building).
For example:
5 5 E E E B E E B E E E E E E E E E B E E E E E E B E
outputFormat
Output a single integer to the standard output (stdout) representing the length of the longest contiguous street (sequence of empty cells) in the city map.## sample
5 5
E E E B E
E B E E E
E E E E E
E B E E E
E E E B E
5