TopcoderArchive
Archive
Algorithm problem

EllysWeirdTool

Problem statement, definition, constraints, and public examples.

Problem Statement

Elly has a weird tool that can manipulate strings. It works as follows: The girl chooses two distinct indices of а string. The characters at these indices get deleted, and, in addition to that, the substring between them gets reversed.

For example let's assume the girl has the string "topcoder". She can use the tool on the indices 1 and 5 (indexed from zero) to obtain "topcoder" -> "tocper". After that she can use it on the 'o' and 'e' to obtain "tpcr". Finally, she can use it on the 'p' and 'c' to obtain "tr".

The girl initially has the String S. She wants to obtain the lexicographically largest possible string that can be derived from it by using the tool zero or more times. Help her by writing a method that returns the desired result.

Definition

Class:
EllysWeirdTool
Method:
getLargest
Parameters:
String
Returns:
String
Method signature:
String getLargest(String S)
(be sure your method is public)

Constraints

  • S will contain between 1 and 13 characters, inclusive.
  • Each character of S will be a lowercase letter from the English alphabet.

Examples

  1. "topcoder"
    Returns: "tr"
    The example from the problem statement.
  2. "zle"
    Returns: "zle"
    Sometimes it is best to not use the tool at all.
  3. "aquiz"
    Returns: "z"
    It is possible that a string is trimmed to a single character.
  4. "fireandblood"
    Returns: "roondb"
  5. "thecakeisalie"
    Returns: "tslkeee"
    This was a triumph...
  6. "esprit"
    Returns: "st"
Back to all problems