Statistics

Problem Statement for "LexmaxReplace"

Problem Statement

Alice has a string s of lowercase letters. The string is written on a wall.

Alice also has a set of cards. Each card contains a single letter. Alice can take any card and glue it on top of one of the letters of s. She may use any subset of cards in this way, possibly none or all of them. She is not allowed to glue new letters in front of s or after s, she can only replace the existing letters.

Alice wants to produce the lexicographically largest possible string.

You are given the String s. You are also given a String t. Each character of t is a letter written on one of the cards. Compute and return the lexicographically largest string Alice can produce on the wall while following the rules described above.

Definition

Class:
LexmaxReplace
Method:
get
Parameters:
String, String
Returns:
String
Method signature:
String get(String s, String t)
(be sure your method is public)

Notes

  • Given two distinct strings X and Y of the same length, the lexicographically larger one is the one that has a larger character on the first position on which they differ.

Constraints

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

Examples

  1. "abb"

    "c"

    Returns: "cbb"

    Alice has a single card. This card contains the letter 'c'. The optimal solution is to glue it on top of s[0], producing the string "cbb".

  2. "z"

    "f"

    Returns: "z"

    Here the optimal solution is to do nothing. The card with the letter 'f' will remain unused.

  3. "fedcba"

    "ee"

    Returns: "feeeba"

  4. "top"

    "coder"

    Returns: "trp"

  5. "abcdefgh"

    "zzz"

    Returns: "zzzdefgh"

  6. "ittmcsvmoa"

    "jktvvblefw"

    Returns: "wvvtlsvmok"

  7. "e"

    "v"

    Returns: "v"

  8. "ns"

    "pd"

    Returns: "ps"

  9. "vux"

    "dap"

    Returns: "vux"

  10. "twnwdluhxf"

    "l"

    Returns: "twnwlluhxf"

  11. "z"

    "a"

    Returns: "z"

  12. "xldyzmsrrwzwaofkcxwehgvtrsximxgdqrhjthkgfucrjdvwlr"

    "xfpidmmilhdfzypbguentqcojivertdhshstkcysydgcwuwhlk"

    Returns: "zyyyzyxwwwzwvuuttxwtssvtssxrqxppqrontmmllukrkjvwlr"

  13. "snzbzdhdqwkypuhjuceesufdcealugqlpzznoyshkiusnshztx"

    "mcuyjocgzozkwxbmvkeaippvlbcrml"

    Returns: "zzzyzxwvvwuyruppuoomsummllklukqlpzznoysjkiusnsiztx"

  14. "novfytvosvwbeykfnkkebgonntfqapbuphspjsclowovrgraef"

    "ayzpqprgpu"

    Returns: "zyvuytvrsvwqpyppnkkgbgonntfqapbuphspjsclowovrgraef"

  15. "dghasierphdvftmajflqcdasjrrbcvpjwoqvpghlvushndlzsc"

    "rdc"

    Returns: "rghdsierphdvftmcjflqcdasjrrbcvpjwoqvpghlvushndlzsc"

  16. "pdgzvgvgbichiiqdhytvcooetcgeecyueoylqzbtzzgaqhaltk"

    "l"

    Returns: "plgzvgvgbichiiqdhytvcooetcgeecyueoylqzbtzzgaqhaltk"

  17. "psafelqnoe"

    "eflqypyqecbrvxyoagogravxvlmrirxitihomztvjmenihqvfu"

    Returns: "zyyyxxxvvv"

  18. "k"

    "fjjkrunjelpdqzqepwxuhcwangcpjoglfqfnbbdjxnedxxmqfa"

    Returns: "z"

  19. "tpcpozrqczoacmxqkxhqrpgguvgrwh"

    "jitccdjpuzxgevgdefezcvxltkaphnaekjgsghsjjxciquovwj"

    Returns: "zzxxxzwvvzvuutxtsxsqrqppuvorwn"

  20. "uaqgvfdqlzukoaonfjdyzzzyhsoafcugmeqsyhyn"

    "veypezailnaofjyxfywyosfqxisoxxchpxncentbnzzgktuccd"

    Returns: "zzzyyyyxxzxxxwvuttsyzzzyssqppouoonqsynyn"

  21. "y"

    "hc"

    Returns: "y"

  22. "td"

    "m"

    Returns: "tm"

  23. "hg"

    "pqh"

    Returns: "qp"

  24. "h"

    "jzjjqeiufojzuyved"

    Returns: "z"

  25. "pjk"

    "nnfj"

    Returns: "pnn"

  26. "kgan"

    "rtm"

    Returns: "trmn"

  27. "a"

    "b"

    Returns: "b"

  28. "xzy"

    "zz"

    Returns: "zzz"

  29. "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"

    "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"

    Returns: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"

  30. "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"

    "z"

    Returns: "zaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"

  31. "xx"

    "aaaaaaaaaaaaaaaaaaaaaaazaaaaaaaaaaaaaaaaaaaaaaaaaa"

    Returns: "zx"

  32. "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"

    "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"

    Returns: "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"

  33. "aa"

    "zx"

    Returns: "zx"

  34. "aaaaa"

    "zzzzz"

    Returns: "zzzzz"

  35. "xx"

    "yz"

    Returns: "zy"


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: