TopcoderArchiveVisit Topcoder
SRM16 Mar 2005
SRM 234

ComboLength

Problem statement, definition, constraints, and public examples.

Problem Statement

You are given a String composed of A's and B's. Each A and B denotes a move performed by players A and B, respectively. Return the length of the longest combo performed by either player. A combo is a string of moves executed by a player that is not interrupted by the opposing player (see the examples for further clarification).

Definition

Class:
ComboLength
Method:
howLong
Parameters:
String
Returns:
int
Method signature:
int howLong(String moves)
(be sure your method is public)

Constraints

  • moves will contain between 2 and 50 characters inclusive.
  • Each character of moves will be A or B.

Examples

  1. "AAA"
    Returns: 3
    Player A executes 3 moves in a row.
  2. "AAABBBBAA"
    Returns: 4
    Player A executes 2 combos of length 3 and 2 respectively. Player B executes a single combo of length 4.
  3. "BBAABBAABBAABBAA"
    Returns: 2
  4. "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
    Returns: 50
  5. "AAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAA"
    Returns: 25
Back to all problems