TopcoderARCHIVE
Archive/Problems/GoodSubstrings
SRM · Problem 13902

GoodSubstrings

Problem statement, definition, constraints, and public examples.

Problem Statement

You are given a string s consisting of lower case English letters and '.'. A string is called good if all of its characters are equal, e.g. "aaa" is good whereas "aab" is not.

Each '.' should be replaced by a letter ('a' - 'z') so as to maximize number of good substrings in s. Return the maximum number of possible good substrings you can have.

Definition

Class:
GoodSubstrings
Method:
maxGoodSubstrings
Parameters:
String
Returns:
int
Method signature:
int maxGoodSubstrings(String s)
(be sure your method is public)

Constraints

  • Number of characters in s will be between 1 and 500, inclusive.
  • Each character of s will be a lower case English letter ('a' to 'z') or '.'.

Examples

  1. "aab"
    Returns: 4
    Following 4 substrings are good. Assume 1 based indexing. s[1, 1] = "a", s[1, 2] = "aa", s[2, 2] = "a", s[3, 3] = "b".
  2. "a."
    Returns: 3
    You can fill '.' by 'a' and get string "aa" whose all three substrings are good.
  3. "enjoy..the..problem"
    Returns: 25
  4. "topcoder.is.quite...good..imho...."
    Returns: 56
  5. ".acb.a.cbcac..b.b..bb.caaacbac.abcab..bbababcb.aa."
    Returns: 119
← All problems