Statistics

Problem Statement for "ListeningIn"

Problem Statement

You are creating an online multiplayer cooperative game. Players on a team may chat with each other during the game, and you intend to take advantage of this when building the AI to handle opponents. Part of the AI includes determining whether a given phrase is part of a player's chat. Of course, many variations of a given phrase are possible, and you want to detect as many as you can. Shorthand is the most common example: instead of typing 'capture', a player might type 'cptr', or 'port to me' instead of 'teleport to me'. You will be provided with a String typed typed by a player and a phrase that you wish to check against. Return the characters removed from phrase to obtain typed in the order they appear in phrase or "UNMATCHED" if there is no way to obtain typed from phrase by simply removing characters. The constraints ensure that the return is unique (there is only one option for which String is returned).

Definition

Class:
ListeningIn
Method:
probableMatch
Parameters:
String, String
Returns:
String
Method signature:
String probableMatch(String typed, String phrase)
(be sure your method is public)

Constraints

  • typed and phrase will contain only lowercase letters ('a'-'z') and spaces
  • typed and phrase will be between 1 and 50 characters long, inclusive.
  • All valid groups of characters that could be removed to turn phrase into typed will give the same output.

Examples

  1. "cptr"

    "capture"

    Returns: "aue"

    The example given in the problem statement.

  2. "port to me"

    "teleport to me"

    Returns: "tele"

    The other example from the statement.

  3. "back to base"

    "back to base"

    Returns: "UNMATCHED"

    An extra space has been added; we do not account for additions, only deletions.

  4. "b"

    "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"

    Returns: "UNMATCHED"

  5. "xgqa"

    "xgqap"

    Returns: "p"

  6. "jhgmpql k"

    "jhgmpql f nkp"

    Returns: "fnp"

  7. "ekxlqccpkupbmkumlxmrte jxxfwfmlg"

    "epkxlqccpkupbmkumlxmrtet jxxfwfhumlg"

    Returns: "pthu"

  8. "ahdnbo wizdrqw sbrpf"

    "oeashswdnbo wicszvdr qw sbrpf"

    Returns: "oesswcsv "

  9. "dxc "

    "haidbcxcvqjfwxqhawnvi gkcb"

    Returns: "haibcvqjfwxqhawnvigkcb"

  10. "hzofohno nusesuvvupgufsufmzmclgnyyrzb"

    "hzofohnou nusesuvvupgufstufmzmclgnyyrzb"

    Returns: "ut"

  11. "ha zjdowpqkjetdsamkkegdna"

    "okha nzjdowpqbkjetdsamqbkvepgqvjqmdmna"

    Returns: "UNMATCHED"

  12. "tquko"

    "wgtmyqqufaavattclsnliwkbgxxbeovtewu"

    Returns: "wgmyqfaavattclsnliwbgxxbevtewu"

  13. "jgtecajceo qnsnzfctvgvfwmmpijxyzslapjecyhbjx"

    "jgtecajceo qnsnzfctvgvfwmmpijxyzslapjecyhbjx"

    Returns: ""

  14. "cibnt"

    "ciab"

    Returns: "UNMATCHED"

  15. "pduashdeaqmxbfur"

    "pduashdekaqmdbfu"

    Returns: "UNMATCHED"

  16. "obaehxxpebhckt htgvif"

    "obaulrethpjebeyhwfckit rhtbgwiviogf"

    Returns: "UNMATCHED"

  17. "torgldqjlodz pxgi"

    "ctorgscpjvldqjloxdoz pxgei"

    Returns: "cscpjvxoe"

  18. "tqmcwonoqnl"

    "tqmcvwolnoqnl"

    Returns: "vl"

  19. "v"

    "vg"

    Returns: "g"

  20. "monaylqnsam"

    "monaaylqnsyam"

    Returns: "ay"

  21. "vhmizpdpb"

    "vhdrmizipdzpbb"

    Returns: "drizb"

  22. "it"

    "i"

    Returns: "UNMATCHED"

  23. "japfpaw"

    "jpfaw"

    Returns: "UNMATCHED"

  24. "viodeffspziylbf vtpxkjjspiltfi"

    "ocpvhbikodeffspzsiydlbfa vtpxkqjjsupiltgrcf"

    Returns: "UNMATCHED"

  25. "bj"

    "jb"

    Returns: "UNMATCHED"

  26. "xh wpamkxnkghogh"

    "xh wpamkxnskghoghc"

    Returns: "sc"

  27. "tiddfkkeupfmwpzsvcrnfi"

    "tiddfkkeupafmwpzsvrnfi"

    Returns: "UNMATCHED"

  28. "kchbezg qqearnpofiuuzniecuohnwjhgjnpdvyyp"

    "kcbezg qqeanpofiuuzniecuohtnwjhgfjnpdvyyp"

    Returns: "UNMATCHED"

  29. " lty mah"

    "q ubmetyau mzahrzd"

    Returns: "UNMATCHED"

  30. "snytpoetekfcdeh"

    "snythwpoetekvpfcdeh"

    Returns: "hwvp"

  31. "svugvadwvqpzpy"

    "svugevzadwvkwhrqpsngzpyb"

    Returns: "ezkwhrsngb"

  32. "zq"

    "zfsg"

    Returns: "UNMATCHED"

  33. "d khrpqypv"

    "omdxcbxhhqirgpqyujtmpryvv"

    Returns: "UNMATCHED"

  34. "muyinlyycun"

    "mluyiar nxhilyyqfcyun"

    Returns: "lar xhiqfy"

  35. " telrhibqq mbwquv "

    " uteqvldrxvvqtxhaibbqbtqupnvb mkacj bjwkzpquv "

    Returns: "uqvdxvvqtxabbtupnvbkacj jkzp"

  36. "port to me"

    "teleport to me"

    Returns: "tele"

  37. "cptn"

    "capture"

    Returns: "UNMATCHED"

  38. "cptrb"

    "capture"

    Returns: "UNMATCHED"

  39. "mad"

    "damm"

    Returns: "UNMATCHED"

  40. "asdf"

    "asdf"

    Returns: ""

  41. "cpture"

    "capptture "

    Returns: "apt "

  42. "cptir"

    "capture"

    Returns: "UNMATCHED"

  43. "vladut are"

    "v adut are"

    Returns: "UNMATCHED"

  44. "cptr"

    "capture e"

    Returns: "aue e"

  45. "ab"

    "ba"

    Returns: "UNMATCHED"

  46. "sadfsadfdsafsdf"

    "lkjlkjlksakfsljfsafjslakfd"

    Returns: "UNMATCHED"

  47. "abc"

    "cba"

    Returns: "UNMATCHED"

  48. "cptr"

    "cptr"

    Returns: ""

  49. "abc"

    "def"

    Returns: "UNMATCHED"

  50. "login"

    "login"

    Returns: ""

  51. "back to"

    "back to base"

    Returns: "UNMATCHED"

  52. "senthil kumar"

    " enthilk suarm"

    Returns: "UNMATCHED"

  53. "lol"

    "laugh out loud"

    Returns: "augh ut oud"

  54. "back to base"

    "backe ato ba se"

    Returns: "e a "

  55. "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"

    "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"

    Returns: ""

  56. "xzvhsfxcj xhxdhiaxfa nmww yjxuohu vnxtqphup"

    "xpzvhsfxficj xhxdhia xfa nmmww yjxuohu vnxtyqphup"

    Returns: "pfi my"

  57. "back to bse"

    "back to basee"

    Returns: "UNMATCHED"

  58. "abs"

    "abfjdkfjd"

    Returns: "UNMATCHED"

  59. "senthil kumar rajja"

    " enthilk suarm jar"

    Returns: "UNMATCHED"

  60. "a"

    "a"

    Returns: ""

  61. "xy"

    "xzz"

    Returns: "UNMATCHED"

  62. "ab"

    " ab"

    Returns: " "

  63. "abcf"

    "abcde"

    Returns: "UNMATCHED"

  64. "a"

    " ab"

    Returns: " b"

  65. "back to base"

    "back to base"

    Returns: "UNMATCHED"

  66. "aaaaa"

    "aaaaa"

    Returns: ""

  67. "a b"

    "a b"

    Returns: " "

  68. "a f f a a f "

    "a f a a fgfdgfd"

    Returns: "UNMATCHED"

  69. "a"

    "z"

    Returns: "UNMATCHED"

  70. "abcd"

    "abcdddd"

    Returns: "ddd"

  71. "bbbbbbbbbbbbbbbbbbbbbbbbbb"

    "ababababababababababababababababababababababababab"

    Returns: "UNMATCHED"

  72. "aaa"

    "aaaabbbbbcccc"

    Returns: "abbbbbcccc"

  73. "cptr one"

    "captured"

    Returns: "UNMATCHED"

  74. "a"

    "b"

    Returns: "UNMATCHED"

  75. "btw"

    "by the way"

    Returns: "y he ay"

  76. "acp"

    "capture"

    Returns: "UNMATCHED"

  77. "back to back"

    "back to back"

    Returns: ""

  78. "a"

    "bb"

    Returns: "UNMATCHED"

  79. "a b"

    "a b b"

    Returns: " b"

  80. "capture"

    "capture"

    Returns: ""

  81. "a"

    "abcd"

    Returns: "bcd"


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: