TopcoderArchive
Archive
Algorithm problem

FiveRooksDiv2

Problem statement, definition, constraints, and public examples.

Problem Statement

You have an 8x8 chessboard. Each cell is either empty or contains a single rook. You are given a description of the chessboard in the String[] board. Empty cells are represented by '.' (period), rooks are represented by 'R'.

You would like to know the maximum number of rooks that appear in the same row or in the same column. Return this count.

Definition

Class:
FiveRooksDiv2
Method:
findMax
Parameters:
String[]
Returns:
int
Method signature:
int findMax(String[] board)
(be sure your method is public)

Constraints

  • board will have exactly 8 elements.
  • Each element of board will have exactly 8 characters.
  • Each character of board will be '.' or 'R'.

Examples

  1. {
    "RRRRRRRR",
    "RRRRRRRR",
    "RRRRRRRR",
    "RRRRRRRR",
    "RRRRRRRR",
    "RRRRRRRR",
    "RRRRRRRR",
    "RRRRRRRR"
    }
    Returns: 8
  2. {
    "R......R",
    ".R....R.",
    "..R..R..",
    "...RR...",
    "...RR...",
    "..R..R..",
    ".R....R.",
    "R......R"
    }
    
    Returns: 2
  3. {
    "R.R.R.RR",
    "........",
    "R.R.R.RR",
    "........",
    "........",
    "........",
    "R.R.R.RR",
    "........"
    }
    
    
    Returns: 5
  4. {
    "R.R.R.RR",
    "........",
    "R.R.R.RR",
    "R.R.R.RR",
    "R.R.R.RR",
    "R.R.R.RR",
    "R.R.R.RR",
    "........"
    }
    Returns: 6
  5. {
    "........",
    "........",
    "........",
    "........",
    "........",
    "........",
    "........",
    "........"
    }
    
    Returns: 0
Back to all problems