Problem Statement
Cat Taro has a square grid with N rows and N columns. Each cell of the grid is painted either black or white. You are given a String[] grid which represents the current state of the grid. Each element of grid represents one row of the grid. In grid, the character 'W' represents a white cell, and the character 'B' represents a black cell.
Taro wants to choose a set of consecutive cells that are in the same column and are painted in the same color. Return the largest number of cells he can choose.
Definition
- Class:
- TaroGrid
- Method:
- getNumber
- Parameters:
- String[]
- Returns:
- int
- Method signature:
- int getNumber(String[] grid)
- (be sure your method is public)
Constraints
- N will be between 1 and 50, inclusive.
- grid will contain exactly N elements.
- Each element of grid will contain exactly N characters.
- Each character in grid will be 'W' or 'B'.
Examples
{"W"}Returns: 1
{"WB", "BW"}Returns: 1
{"BWW", "BBB", "BWB"}Returns: 3
He can choose the entire leftmost column (i.e., character 0 of each element of grid).{"BWBW", "BBWB", "WWWB", "BWWW"}Returns: 3
{"BWB", "BBW", "BWB"}Returns: 3
{"BBWWBBWW", "BBWWBBWW", "WWBBWWBB", "WWBBWWBB", "BBWWBBWW", "BBWWBBWW", "WWBBWWBB", "WWBBWWBB"}Returns: 2
Note that the chosen cells must be consecutive.