Statistics

Problem Statement for "ErasingCharacters"

Problem Statement

Fox Ciel received a string as a birthday present. However, the string was too long for her, so she decided to make it shorter by erasing some characters.

The erasing process will look as follows:
  1. Find the smallest i such that the i-th character and the (i+1)-th character of the string are same.
  2. If there is no such i, end the process.
  3. Remove the i-th and the (i+1)-th character of the string, and repeat from 1.


For example, if she receives "cieeilll", she will change the string as follows: "cieeilll" -> "ciilll" -> "clll" -> "cl". You are given a String s. Return the string she will get after she erases characters as described above.

Definition

Class:
ErasingCharacters
Method:
simulate
Parameters:
String
Returns:
String
Method signature:
String simulate(String s)
(be sure your method is public)

Constraints

  • s will contain between 1 and 50 characters, inclusive.
  • Each character in s will be a lowercase letter ('a'-'z').

Examples

  1. "cieeilll"

    Returns: "cl"

    This is the example from the statement.

  2. "topcoder"

    Returns: "topcoder"

    She won't erase any characters at all.

  3. "abcdefghijklmnopqrstuvwxyyxwvutsrqponmlkjihgfedcba"

    Returns: ""

  4. "bacaabaccbaaccabbcabbacabcbba"

    Returns: "bacbaca"

  5. "eel"

    Returns: "l"

  6. "phhzonmhoiicmiopdhaopzqochdzpdocomhayiaiaymynpoyoq"

    Returns: "pzonmhocmiopdhaopzqochdzpdocomhayiaiaymynpoyoq"

  7. "lumrnjcwxeqpftdkeaoirxxnjamvgiknvipjgryfzdaoljqlic"

    Returns: "lumrnjcwxeqpftdkeaoirnjamvgiknvipjgryfzdaoljqlic"

  8. "bottwzhnwytoyubnbotwuztoutotttzyuuzohnzuolbtbbollt"

    Returns: "bowzhnwytoyubnbotwuztoutotzyzohnzuolbtot"

  9. "pfcfiitmjvijcswwyvplathfzzrrvrxrysnrcqklpmmekjkpcy"

    Returns: "pfcftmjvijcsyvplathfvrxrysnrcqklpekjkpcy"

  10. "rddrdssrrrrdddxrsxsrddrrrrrdrsxrxrrsdxrxssrsrxsdsx"

    Returns: "xrsxsdrsxrxsdxrxrsrxsdsx"

  11. "vppbpvpbdbbbdvvvpbvpbbvvvbppppbpbvbbvvppppbbbpdpbd"

    Returns: "vbpvpbdbdvpbvpvpbvbpdpbd"

  12. "ugzchppfhucfxafcfucjhggjgjgpzzhfzgafxhhhczgxhhgjha"

    Returns: "ugzchfhucfxafcfucjhjgjgphfzgafxhczgxgjha"

  13. "rurcmcdsmrcdddscmsrucsduscuudrmdrusucsmmdccdusdsms"

    Returns: "rurcmcdsmrcdscmsrucsduscdrmdrusucsusdsms"

  14. "odgywouyodwjyfdoyiyugfhjdguufgionecfghcgiynhydjyyw"

    Returns: "odgywouyodwjyfdoyiyugfhjdgfgionecfghcgiynhydjw"

  15. "cpaafwuhqurhuarbufaxxonuxwucoxcxfqxqrpxxxfcbcfawqo"

    Returns: "cpfwuhqurhuarbufaonuxwucoxcxfqxqrpxfcbcfawqo"

  16. "wlbksnjktm"

    Returns: "wlbksnjktm"

  17. "mmrwscgyyeho"

    Returns: "rwscgeho"

  18. "difddididfdiiidddfififidi"

    Returns: "difididfdidfififidi"

  19. "wksoaxbkshobugyzsbwl"

    Returns: "wksoaxbkshobugyzsbwl"

  20. "jwygypu"

    Returns: "jwygypu"

  21. "baiucuqjrzbqtjdzadubbdzuaridajburbbczjztjzqa"

    Returns: "baiucuqjrzbqtjdzadudzuaridajburczjztjzqa"

  22. "eeeeeeeeeeeeeeeeeeeee"

    Returns: "e"

  23. "esinghaaggn"

    Returns: "esinghn"

  24. "lsjnjdpcdptkclzbst"

    Returns: "lsjnjdpcdptkclzbst"

  25. "wwvovvoxwwowxxvoxovoxvovvxxxooxvwoowwxvxowooxovvoo"

    Returns: "vxowvoxovoxvovwxvxowxo"

  26. "cccccccccccccccccccccccccccccccccccccccccccccccccc"

    Returns: ""

  27. "b"

    Returns: "b"

  28. "abcca"

    Returns: "aba"

  29. "aba"

    Returns: "aba"

  30. "all"

    Returns: "a"

  31. "aaaa"

    Returns: ""

  32. "caacb"

    Returns: "b"

  33. "aaaab"

    Returns: "b"


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: