Statistics

Problem Statement for "ContainedPalindromes"

Problem Statement

Class name: ContainedPalindromes
Method name: getPalindromes
Parameters: String
Returns: String[]

Implement a class ContainedPalindromes, which returns a String[] of the
palindromes contained within a String. (i.e., "aabaac" returns ("aabaa","c").
Every occurrence of every letter in the input stream must be in exactly one
palindrome.  Putting together the Strings in the String[] in order should
result in the input String.  Palindromes are returned in the order they appear
in the String.

A palindrome is a string that is the same forwards or backwards.  A single
character is a palindrome.

Note that it is possible for different sequences of palindromes to be found:
"alolapopa" could return ("alola","pop","a"), or it could return
("a","lol","apopa"), etc...

To resolve such ambiguities, use the following rules:
1. A longer palindrome takes precedence over a smaller one. (For example, in
("abcdcbab", "abcdcba" has the longest length, so it has first precedence, and
{"abcdcba","b"} should be returned)
2. The first of two palindromes of equal length takes precedence. (For example,
"alolapopa" could return ("alola","pop","a"), or ("a","lol","apopa"), but
"alola" comes before "apopa", so the returned String[] should contain alola.)

Here is the method signature (be sure your method is public):
String[] getPalindromes(String input);

input will be between 1 and 50 letters in length, and will contain only letters
of the (both uppercase and lowercase). TopCoder will check this.

Note that the problem is NOT case sensitive: "aBA" is a palindrome.  However,
characters in the result must have the same case as they did in the input - if
"aBA" is a palindrome, it must be returned as "aBA".

For instance (quotes are included here for clarity, but not in the actual
Strings):
"aaBaacAa" returns {"aaBaa","c","Aa"}.
"aABaaacaaada" returns {"aA","B","aaacaaa","d","a"}.
"abcdcbab" returns {"abcdcba","b"}
"alolapopa" returns {"alola","pop","a"}
"alolappopalola" returns {"alola","p","pop","alola"} Note - alola must be
returned twice in this example.

Definition

Class:
ContainedPalindromes
Method:
getPalindromes
Parameters:
String
Returns:
String[]
Method signature:
String[] getPalindromes(String param0)
(be sure your method is public)

Constraints

    Examples


      This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
      This problem was used for: