Statistics

Problem Statement for "MakeUnique"

Problem Statement

Given a sequence of uppercase letters, we want to remove all but one occurrence of each letter, doing it in such a way that the remaining letters are in alphabetical order. Of course, there may be no way to do this, but if there is, we want to know which letters to remove.

Create a class MakeUnique that contains a method eliminated that is given a String original, and returns original with the eliminated letters replaced with periods ('.'). The remaining letters must be in alphabetical order.

If there is no way to do this, return a String with length 0.

If there are several ways to do this, choose the one with the shortest length between the first and last remaining letters. If there are still several ways, return the String among these that comes earliest lexicographically ('.' comes earlier than any letter in the ASCII sequence).

Definition

Class:
MakeUnique
Method:
eliminated
Parameters:
String
Returns:
String
Method signature:
String eliminated(String original)
(be sure your method is public)

Constraints

  • original will contain between 1 and 50 characters inclusive
  • each character in original will be an uppercase letter 'A'-'Z'

Examples

  1. "ABBBXCXABCX"

    Returns: ".......ABCX"

    The 4 letters ABCX must remain, and in that order. "AB...CX...." would also leave these letters in the appropriate order, but the length between the first and last remaining letters would be longer than in the given answer.

  2. "ABBBXCXABCB"

    Returns: "A..B.CX...."

    "AB...CX...." and "A.B..CX...." are also possible and have the same length between first and last remaining letters, but they come later lexicographically than the given answer.

  3. "ABBBXCABCB"

    Returns: ""

    There is no way to eliminate letters and end up with C before X.

  4. "AABACBXABX"

    Returns: ".AB.C.X..."

  5. "CABDEAFDEGSDABCDEADFGSEFBGS"

    Returns: "............ABCDE..FGS....."

  6. "AAAAAA"

    Returns: ".....A"

  7. "AABCDEFGGGGGGGGGGGGGGGGGGGGGGGHIJKLMNOPQRSTUVWXYZZ"

    Returns: ".ABCDEF......................GHIJKLMNOPQRSTUVWXYZ."

  8. "X"

    Returns: "X"

  9. "ABCBCABCBABCCBABBCBBCABCAABCAB"

    Returns: ".........................ABC.."

  10. "ABCBCABCBABCCBABBCBBCABAAABBAB"

    Returns: ".........ABC.................."

  11. "ABDDCBCABCBABCCBABBCBBCABAAABBAB"

    Returns: ""

  12. "ACBCABAAACBBBCCBABBACBBCABAAABBAB"

    Returns: "A.BC............................."

  13. "ACBACABAAACBBBCCBABBACBBCABAAABBAB"

    Returns: "....................A..BC........."

  14. "GD"

    Returns: ""

  15. "ABCDCDDDDDACDCDCDCCCCCDEBCAAACADAEACBDCD"

    Returns: "..........A.............B....C.D.E......"

  16. "ABDCDDDDDACDCDCDCCCCCDEBCAAACADAEACBDCD"

    Returns: "AB..................CDE................"

  17. "ACBCAEBCBEFEECFAACAEDECFDFAECFDAADDCFEADCBDDBDDDEE"

    Returns: "....A...B........C..DE.F.........................."

  18. "DACBCBDDDDCBCDADABDCCCDCCADBACCB"

    Returns: ".A.BC.D........................."

  19. "AC"

    Returns: "AC"

  20. "DEBEECCABCDEEAAADCBCADAEBB"

    Returns: ".......ABCDE.............."

  21. "EEF"

    Returns: ".EF"

  22. "C"

    Returns: "C"

  23. "GDEEFCHDCGGHCCEHBICBBDEBBBFGBIGEEIHIDIHCHBHBGDCC"

    Returns: "................B.C..DE...F...G...HI............"

  24. "CACBBCBCABBBCBACBAB"

    Returns: "........A..BC......"

  25. "BBACBCCAABABBA"

    Returns: "..A.BC........"

  26. "BABBCACBCBCBAA"

    Returns: ".....A.BC....."

  27. "BCCABCACABBABBBAABCAABCCBABCBBBBACCA"

    Returns: ".........................ABC........"

  28. "BF"

    Returns: "BF"

  29. "DBADADBABDCBCBBCBDCBABDCAADCDCDACCBBBBDBABBABBCCA"

    Returns: "....................AB.C..D......................"

  30. "BDBABEBCDCACDECCEDCCBBDBECABEDEDAAACBDBBACAEEDED"

    Returns: "...A..B....CDE.................................."

  31. "BABCBADBACBBBDCAADDADBBACACBB"

    Returns: ".ABC..D......................"

  32. "ADCABAEAEDECDDCEDABBCEABBBEAAAACCEEECBECBCCECBC"

    Returns: "...AB......C.D.E..............................."

  33. "BDEDFDEF"

    Returns: "BDE.F..."

  34. "BAACDBBCBABDCCBBAADCAA"

    Returns: ".........AB..C....D..."

  35. "EDEEAEBCEBAECEEEEEADEBCCEACABDBEAAEBDBDCAEABCAE"

    Returns: "..................A..B....C..D.E..............."

  36. "AI"

    Returns: "AI"

  37. "CGBFEEDCCECCEGFFCFDABDABGCFFEADAEBDDCAAADDCDFGGF"

    Returns: "......................AB.C....D.E...........FG.."

  38. "BEEABDCCDCABAEAABCDCCBABCEAEAABEBABBEDBBC"

    Returns: "...............ABCD......E..............."

  39. "DDCCADAABACCCDCAABCCACDCCDCCDD"

    Returns: "................AB...CD......."

  40. "CACBCCC"

    Returns: ".A.BC.."

  41. "ADBBABDCDAB"

    Returns: "....AB.CD.."

  42. "G"

    Returns: "G"

  43. "ABCCBCBBBBBBBABCBAAABBBAABABBCBCBBBBCABCCCC"

    Returns: ".....................................ABC..."

  44. "EEAEADECCEADBEEFEFCDFFDEFFFAFADEACDFCFBBEFBAD"

    Returns: "..........A.B.....C...DEF...................."

  45. "BBCEBBCC"

    Returns: ".BCE...."

  46. "BBBCBCBDABAABBBABCAACDCCCDDCCADDACAC"

    Returns: "...............AB...CD.............."


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: