Statistics

Problem Statement for "SistersErasingLetters"

Problem Statement

Camomile and her twin sister Romashka are playing a game. At the beginning of the game, they are given a word. Then, starting with Camomile, they take alternate turns, and on each turn, the player erases one letter from the word. That letter must be at a position greater than or equal to the position of the letter erased on the previous turn (on the first turn, the player can erase any letter). Letter positions are numbered consecutively from left to right and are renumbered from scratch after each turn. For example, if the word is "topcoder" and a player erases the letter 'c', the word would become "topoder", and on the next turn, the other player could only erase the letters 'r', 'e', 'd' or the second 'o'.

When a player erases the last letter, the game ends. If the word at the end of the game is lexicographically greater than the word at the beginning, Camomile wins. Otherwise, Romashka wins. You are given a String word, which is the word given at the beginning of the game. Assuming that Romashka and Camomile both play optimally, return "Romashka" if Romashka will win or "Camomile" if Camomile will win (all quotes for clarity).

Definition

Class:
SistersErasingLetters
Method:
whoWins
Parameters:
String
Returns:
String
Method signature:
String whoWins(String word)
(be sure your method is public)

Notes

  • A string X is defined as smaller than a string Y if and only if X is a prefix of Y or X has a smaller character than Y at the first position where they differ.

Constraints

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

Examples

  1. "topcoder"

    Returns: "Camomile"

    1. Camomile starts by erasing the letter 'c', leaving "topoder". 2. It doesn't matter what Romashka erases on her turn. The possible outcomes of this turn are "topder", "topoer", "topodr" and "topode". In the last outcome, Romashka deletes the last letter and ends the game, but loses. 3. If Romashka doesn't end the game, then Camomile will end it by erasing the last letter. The possible outcomes are "topde", "topoe" and "topod", all of which are lexicographically greater than "topcoder".

  2. "program"

    Returns: "Romashka"

    Camomile can't win here.

  3. "abcd"

    Returns: "Camomile"

    Here, Camomile can only win if she starts by erasing the letter 'a'.

  4. "abc"

    Returns: "Romashka"

    Note that the empty string is lexicographically smaller than any other string.

  5. "easyproblemroundfivetopcoderopentwothousandeleven"

    Returns: "Camomile"

  6. "vzwxuvstqropmnklijghefcdab"

    Returns: "Camomile"

  7. "wzwxuvstqropmnklijghefcdab"

    Returns: "Romashka"

  8. "yzwxuvstqropmnklijghefcdab"

    Returns: "Romashka"

  9. "yzazbzczdzezfzgzhzizjzkzlzmznzozpzqzrzsztzuzvzwzxz"

    Returns: "Camomile"

  10. "abaca"

    Returns: "Camomile"

  11. "aabbbb"

    Returns: "Camomile"

  12. "aaaa"

    Returns: "Romashka"

  13. "aaab"

    Returns: "Romashka"

  14. "aaba"

    Returns: "Romashka"

  15. "aabb"

    Returns: "Romashka"

  16. "aabc"

    Returns: "Romashka"

  17. "aacb"

    Returns: "Romashka"

  18. "abaa"

    Returns: "Romashka"

  19. "abab"

    Returns: "Romashka"

  20. "abac"

    Returns: "Romashka"

  21. "abba"

    Returns: "Camomile"

  22. "abbb"

    Returns: "Camomile"

  23. "abbc"

    Returns: "Camomile"

  24. "abca"

    Returns: "Camomile"

  25. "abcb"

    Returns: "Camomile"

  26. "abcc"

    Returns: "Camomile"

  27. "acab"

    Returns: "Romashka"

  28. "acba"

    Returns: "Camomile"

  29. "acbb"

    Returns: "Camomile"

  30. "acbc"

    Returns: "Camomile"

  31. "accb"

    Returns: "Camomile"

  32. "baaa"

    Returns: "Romashka"

  33. "baab"

    Returns: "Romashka"

  34. "baac"

    Returns: "Romashka"

  35. "baba"

    Returns: "Romashka"

  36. "babb"

    Returns: "Romashka"

  37. "babc"

    Returns: "Romashka"

  38. "baca"

    Returns: "Romashka"

  39. "bacb"

    Returns: "Romashka"

  40. "bacc"

    Returns: "Romashka"

  41. "bbaa"

    Returns: "Romashka"

  42. "bbab"

    Returns: "Romashka"

  43. "bbac"

    Returns: "Romashka"

  44. "bbba"

    Returns: "Romashka"

  45. "bbca"

    Returns: "Romashka"

  46. "bcaa"

    Returns: "Romashka"

  47. "bcab"

    Returns: "Romashka"

  48. "bcac"

    Returns: "Romashka"

  49. "bcba"

    Returns: "Romashka"

  50. "bcca"

    Returns: "Camomile"

  51. "caab"

    Returns: "Romashka"

  52. "caba"

    Returns: "Romashka"

  53. "cabb"

    Returns: "Romashka"

  54. "cabc"

    Returns: "Romashka"

  55. "cacb"

    Returns: "Romashka"

  56. "cbaa"

    Returns: "Romashka"

  57. "cbab"

    Returns: "Romashka"

  58. "cbac"

    Returns: "Romashka"

  59. "cbba"

    Returns: "Romashka"

  60. "cbca"

    Returns: "Romashka"

  61. "ccab"

    Returns: "Romashka"

  62. "ccba"

    Returns: "Romashka"

  63. "ccbbcbaabc"

    Returns: "Romashka"

  64. "ccbabcbcaa"

    Returns: "Camomile"

  65. "aacabbaccc"

    Returns: "Camomile"

  66. "cacaabcbba"

    Returns: "Camomile"

  67. "cacaacabcb"

    Returns: "Camomile"

  68. "ccbaabcabb"

    Returns: "Camomile"

  69. "bccaabbcbb"

    Returns: "Camomile"

  70. "cacabcaaac"

    Returns: "Camomile"

  71. "acabacbccb"

    Returns: "Camomile"

  72. "aacbcbcaac"

    Returns: "Camomile"

  73. "qpqonymyjxhuhpdbpank"

    Returns: "Romashka"

  74. "zswsljjrjrjhyhlfwaxo"

    Returns: "Romashka"

  75. "wuvqvnhsfeetcncccycl"

    Returns: "Romashka"

  76. "wruoronmjnfufeejecqi"

    Returns: "Romashka"

  77. "txmnlwiyhfheweudbybe"

    Returns: "Romashka"

  78. "wrpzponnvmoiflcucbmj"

    Returns: "Romashka"

  79. "wsxsxsszjwipfeseckak"

    Returns: "Romashka"

  80. "tttlkkyjzdkdcucclbil"

    Returns: "Romashka"

  81. "tyrrqnqnlxlqjjimibvx"

    Returns: "Romashka"

  82. "vsqqqpsookkrkhdazauz"

    Returns: "Romashka"

  83. "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab"

    Returns: "Romashka"

  84. "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaba"

    Returns: "Romashka"

  85. "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaa"

    Returns: "Romashka"

  86. "phqgheayasadabaaoadacacabaaoanajaatacacababaamamaj"

    Returns: "Romashka"

  87. "frbjbaraiabaamababaayacaafadaaeaeacababaaraoacaaea"

    Returns: "Romashka"

  88. "auakajahacacacabaauaayafabaahadababaaeaatahagaarar"

    Returns: "Romashka"

  89. "zrosdqcjcdaayalaeadacaauaababaaiaeadaababababaauan"

    Returns: "Romashka"

  90. "namacacacabababaatamajacabaafaamalababaakaeaayamaf"

    Returns: "Romashka"

  91. "dfcvazaqanakafabaahahahagagagagaataalaadaahahaeaba"

    Returns: "Romashka"

  92. "nhrbdauapaiahahahagagabababaafaanagababaakakagafac"

    Returns: "Romashka"

  93. "kqaxamaeadabaaxaiaazafaasagacabaaxagafaaaiadadacaa"

    Returns: "Romashka"

  94. "mnfhfgeoefbhapahabababaadadaagaeacaatatajafafabaau"

    Returns: "Romashka"

  95. "dvaamafadaacababaapagaaoajaeaeaeaaiaeaeabaamahahah"

    Returns: "Romashka"

  96. "glvwxkyvulcyjeflloqzhltmgtujdcuugnrotlotcpbnyfheje"

    Returns: "Camomile"

  97. "gcmfptqmveghmfbmvklsqfubvxctepvmljohzxxoolnvlayguo"

    Returns: "Camomile"

  98. "kqdauptyvjafzzkqtaxjlrbrukkkigjmxqrbazlpdevpezpbws"

    Returns: "Camomile"

  99. "hvpckldqgivlqpirqvwqquyxpixqireuqamffsvvntguxesidr"

    Returns: "Camomile"

  100. "nwwtqkdozfpkduulifzdpohcgubkurehrqbbxajefbfhkzbpka"

    Returns: "Camomile"

  101. "pbszyspdaaoxraojotjufsturtjhudpetsgrzuigusnwlyrvfn"

    Returns: "Camomile"

  102. "kkmsdbuhvhfqtdvtnlewfquuhtainkebbvzhtqbkdbmvhbsnjb"

    Returns: "Camomile"

  103. "tvjtqnbchiwfuqlzsmxvfjtvquitivyhzpxcdjwikfatcanchx"

    Returns: "Camomile"

  104. "ssjluhlyoebcgnsqfzxxwgliuejobcfpvnyrrpkegeqpvlhxee"

    Returns: "Camomile"

  105. "ocmerjmziudtsqqozvejnrtibvnjepfqdsmvstmmwwwqknnrmq"

    Returns: "Camomile"

  106. "cdccdacade"

    Returns: "Camomile"

  107. "ab"

    Returns: "Romashka"

  108. "bcbee"

    Returns: "Camomile"


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: