TopcoderArchiveVisit Topcoder
SRM26 Jul 2014
SRM 631

TaroGrid

Problem statement, definition, constraints, and public examples.

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

  1. {"W"}
    Returns: 1
  2. {"WB",
     "BW"}
    Returns: 1
  3. {"BWW",
     "BBB",
     "BWB"}
    Returns: 3
    He can choose the entire leftmost column (i.e., character 0 of each element of grid).
  4. {"BWBW",
     "BBWB",
     "WWWB",
     "BWWW"}
    Returns: 3
  5. {"BWB",
     "BBW",
     "BWB"}
    Returns: 3
  6. {"BBWWBBWW",
     "BBWWBBWW",
     "WWBBWWBB",
     "WWBBWWBB",
     "BBWWBBWW",
     "BBWWBBWW",
     "WWBBWWBB",
     "WWBBWWBB"}
    Returns: 2
    Note that the chosen cells must be consecutive.
Back to all problems