Topcoder question 250 points (ANSWERS)

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.