Statistics

Problem Statement for "TheEncryptionDivTwo"

Problem Statement

John is obsessed with security. He is writing a letter to his friend Brus and he wants nobody else to be able to read it. He uses a simple substitution cipher to encode his message. Each letter in the message is replaced with its corresponding letter in a substitution alphabet. A substitution alphabet is a permutation of all the letters in the original alphabet. In this problem, the alphabet will consist of only lowercase letters ('a'-'z').

For example, if John's message is "hello" and his cipher maps 'h' to 'q', 'e' to 'w', 'l' to 'e' and 'o' to 'r', the encoded message will be "qweer". If the cipher maps 'h' to 'a', 'e' to 'b', 'l' to 'c' and 'o' to 'd', then the encoded message will be "abccd".

Given the original message, determine the cipher that will produce the encoded string that comes earliest alphabetically. Return this encoded string. In the example above, the second cipher produces the alphabetically earliest encoded string ("abccd").

Definition

Class:
TheEncryptionDivTwo
Method:
encrypt
Parameters:
String
Returns:
String
Method signature:
String encrypt(String message)
(be sure your method is public)

Notes

  • If A and B are two Strings of the same length, then A comes earlier alphabetically than B if it contains a smaller character at the first position where the Strings differ.

Constraints

  • message will contain between 1 and 50 characters, inclusive.
  • message will contain only lowercase letters ('a'-'z').

Examples

  1. "hello"

    Returns: "abccd"

    The example from the statement.

  2. "abcd"

    Returns: "abcd"

    Here the message is encoded to itself.

  3. "topcoder"

    Returns: "abcdbefg"

  4. "encryption"

    Returns: "abcdefghib"

  5. "adwuaaxcnleegluqvsczaguujoppchwecusmevz"

    Returns: "abcdaaefghiijhdklmfnajddopqqfrcifdmsiln"

  6. "ykquacpkggiianyoolwgykymwraiyigfuxagvwxfkcemiix"

    Returns: "abcdefgbhhiiejakklmhabanmoeiaihpdqehrmqpbfsniiq"

  7. "amyulokgckc"

    Returns: "abcdefghigi"

  8. "aaaabbbaaa"

    Returns: "aaaabbbaaa"

  9. "aaaaaabab"

    Returns: "aaaaaabab"

  10. "abaaabbaa"

    Returns: "abaaabbaa"

  11. "aaaaaaa"

    Returns: "aaaaaaa"

  12. "baaaaaa"

    Returns: "abbbbbb"

  13. "abbaaaaba"

    Returns: "abbaaaaba"

  14. "baaabaaaa"

    Returns: "abbbabbbb"

  15. "bbbbbaa"

    Returns: "aaaaabb"

  16. "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"

    Returns: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"

  17. "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"

    Returns: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"

  18. "zzzzzzzzzzzzzzzzzzzzzzzzzzzzz"

    Returns: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaa"

  19. "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"

    Returns: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"

  20. "iiiijllkiikiikkkijkjkiliikllkiiiiikkik"

    Returns: "aaaabccdaadaadddabdbdacaadccdaaaaaddad"

  21. "liiiiikkijlkikk"

    Returns: "abbbbbccbdacbcc"

  22. "ikjiiijkiiiijlll"

    Returns: "abcaaacbaaaacddd"

  23. "kiiiiikkiiliiiii"

    Returns: "abbbbbaabbcbbbbb"

  24. "kliijiilkkijiikiiklljkiiikkjiikkkiiiiiilkik"

    Returns: "abccdccbaacdccaccabbdacccaadccaaaccccccbaca"

  25. "ouswtvpoqsusuoqwwroruqpswsrrqoowoqooousvuouwuwuuxt"

    Returns: "abcdefgahcbcbahddiaibhgcdciihaadahaaabcfbabdbdbbje"

  26. "oqwtwopsoutoqosovxxxtqwqosooowstououqqsvsoxssvoqst"

    Returns: "abcdcaefagdabafahiiidbcbafaaacfdagagbbfhfaiffhabfd"

  27. "ssquwtxpqosowqrsuqowouwowqtwswqxqwoovwxtoowxsuxsut"

    Returns: "aabcdefgbhahdbiacbhdhcdhdbedadbfbdhhjdfehhdfacface"

  28. "qosvsrrstqouosuwttuowwqsqxowuwqotwwstwowuuwoxuosoo"

    Returns: "abcdceecfabgbcghffgbhhacaibhghabfhhcfhbhgghbigbcbb"

  29. "wtquputtsqooqotoqoootsuussqwooooqsuqtwtqoswvtoqopv"

    Returns: "abcdedbbfcggcgbgcgggbfddffcaggggcfdcbabcgfahbgcgeh"

  30. "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv"

    Returns: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"

  31. "a"

    Returns: "a"

  32. "ffffgggffffffffffgfgffgfffggfffffffffffgfffffff"

    Returns: "aaaabbbaaaaaaaaaababaabaaabbaaaaaaaaaaabaaaaaaa"

  33. "ghdytsrsrtstrggg"

    Returns: "abcdefgfgefegaaa"

  34. "qwerewrewrere"

    Returns: "abcdcbdcbdcdc"

  35. "zabjhkaskbjbkzzxcjkayyasdhkas"

    Returns: "abcdefbgfcdcfaahidfbjjbgkefbg"

  36. "zxcvbnmlkjhgfhjtuiknvdwrtuiknfdfdsaqwertyuiop"

    Returns: "abcdefghijklmkjnopifdqrsnopifmqmqtuvrwsnxopyz"

  37. "asdasdlasdjsdgjskdgsdfsfsdfs"

    Returns: "abcabcdabcebcfebgcfbchbhbchb"

  38. "bbbbbbbbaaaaaaccccc"

    Returns: "aaaaaaaabbbbbbccccc"

  39. "aa"

    Returns: "aa"

  40. "aaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbb"

    Returns: "aaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbb"

  41. "aaz"

    Returns: "aab"

  42. "ddffgggghhggddhtyn"

    Returns: "aabbccccddccaadefg"

  43. "aaaabbbcdbzzadbdbejkghgjeghggeppozhfadzzsaabd"

    Returns: "aaaabbbcdbeeadbdbfghijigfijiifkklejmadeenaabd"

  44. "rjatydimofugclqurclqecdrhvqsuwbvntmryktdl"

    Returns: "abcdefghijklmnokamnopmfaqroskturvdhaewdfn"

  45. "blahblahmammamia"

    Returns: "abcdabcdeceecefc"

  46. "ziang"

    Returns: "abcde"

  47. "abaaba"

    Returns: "abaaba"

  48. "pubaba"

    Returns: "abcdcd"

  49. "z"

    Returns: "a"

  50. "bbd"

    Returns: "aab"

  51. "aaabbbbbaaaaab"

    Returns: "aaabbbbbaaaaab"


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: