TopcoderArchive
Archive
Algorithm problem

MaximalPalindromeSubstrings

Problem statement, definition, constraints, and public examples.

Problem Statement

A palindrome is a string that reads the same forward and backward. A palindrome substring is a contiguous sequence of characters taken from a string that form a palindrome. A palindrome substring of a string is maximal if we can't extend it to get a bigger palindrome substring. For example, string "acdadc" has 2 maximal palindrome substrings - "a" (the first one) and "cdadc". All other palindrome substrings (like "dad" or "c") can be extended to "cdadc", so they are not maximal.

You will be given a String[] str. Concatenate the elements of str to form one long string, and return the number of maximal palindrome substrings contained in that string.

Definition

Class:
MaximalPalindromeSubstrings
Method:
countMaximalPalindromeSubstrings
Parameters:
String[]
Returns:
int
Method signature:
int countMaximalPalindromeSubstrings(String[] str)
(be sure your method is public)

Constraints

  • str will contain between 1 and 50 elements, inclusive.
  • Each element of str will contain between 1 and 50 characters, inclusive.
  • Each character of each element of str will be a lowercase letter ('a'-'z').

Examples

  1. {"acdadc"}
    Returns: 2
    The example from the problem statement.
  2. {"ababab"}
    Returns: 2
    The two maximal palindrome substrings here are "ababa" and "babab".
  3. {"aaaa","bbb","axxx"}
    Returns: 3
    Remember to use the whole input!
  4. {"abacabbacaacdbdcacxcbbbbcabababacccbazhhaahh"}
    Returns: 14
Back to all problems