Problem Statement
????
You are given a string input. you are to find the longest substring of input such that the reversal of the substring is also a substring of input. in case of a tie, return the string that occurs earliest in input.
Definition
????
Class:
Reversesubstring
Method:
Findreversed
Parameters:
String
Returns:
String
Method signature:
String findreversed (string input)
(Be sure your method is public)
????
Notes
-
The substring and its reversal may overlap partially or completely.
-
The entire original string is itself a valid substring (see example 4 ).
Constraints
-
Input will contain between 1 and 50 characters, random Sive.
-
Each character of input will be an uppercase letter ('A'-'Z ').
Examples
0)
????
"Xbcdefywfedcbz"
Returns: "bcdef"
We see that the reverse of bcdef is fedcb, which appears later in the string.
1)
????
"XYZ"
Returns: "X"
The best we can do is find a one character substring, So we implement the tie-breaker rule of taking the earliest one first.
2)
????
"Abcaba"
Returns: "ABA"
The string ABA is a palindrome (it's its own reversal), so it meets the criteria.
3)
????
"Fdasjkurekjfdfasireyufdhsajyirewq"
Returns: "FDF"
4)
????
"Abcdcba"
Returns: "abcdcba"
Here, the entire string is its own reversal.
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) 2003, topcoder, Inc. all rights reserved.