Statistics

Problem Statement for "MarriageAndTravelingChallenge"

Problem Statement

One of the challenges after marriage is traveling to have a great honeymoon. An inseparable part of such travel is hiking in the mountains.

When you shout in the mountains, you can sometimes hear an echo. The echo will say the same thing but it will make it sound longer.

In this problem, we will assume that the echo will repeat the i-th letter of your word i times. (Here we number the letters starting from 1 for the leftmost letter.)

For example, if you say "salam", the echo will say "saalllaaaammmmm".


The fortunate groom has just heard an echo. You are given the sound he heard as a string S of lowercase English letters. It is guaranteed that S was produced from the original word in the way described above. Please determine and return the original word that was said.

Definition

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

Constraints

  • S will contain between 1 and 100 characters, inclusive.
  • Each character in S will be a lowercase English letter.
  • It's guaranteed that S can be produced from some string P by repeating the i-th character of P exactly i times, for each i.

Examples

  1. "saalllaaaammmmm"

    Returns: "salam"

    The example from the problem statement.

  2. "shhaaahhhhdddddaaaaaammmmmmmaaaaaaaaddddddddd"

    Returns: "shahdamad"

  3. "z"

    Returns: "z"

  4. "aaa"

    Returns: "aa"

    The original string was "aa". The first 'a' is repeated once and then the second 'a' is repeated twice.

  5. "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"

    Returns: "aaaaaaaaaaaaa"

  6. "aeerrrttttyyyyyhhhhhhjjjjjjjnnnnnnnnbbbbbbbbbhhhhhhhhhhgggggggggggyyyyyyyyyyyyuuuuuuuuuuuuu"

    Returns: "aertyhjnbhgyu"

  7. "qwweeerrrrtttttyyyyyyqqqqqqqwwwwwwwweeeeeeeeerrrrrrrrrrttttttttttteeeeeeeeeeeeeeeeeeeeeeeee"

    Returns: "qwertyqwertee"

  8. "yzzyyy"

    Returns: "yzy"

  9. "zyyzzzyyyyyyyyy"

    Returns: "zyzyy"

  10. "eaaeeebbbbeeeeeffffffeeeeeee"

    Returns: "eaebefe"

  11. "aaaaaa"

    Returns: "aaa"

  12. "saalll"

    Returns: "sal"


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: