Statistics

Problem Statement for "CardsShuffle"

Problem Statement

You are given a String cards, which represents a sequence of cards. Shuffle the cards by repeatedly performing the specified exchange operation. The exchange operation is specified by the ints first and last, which are both 1-based indices in the sequence. Take all the cards between the first-th card and the last-th card, inclusive, and move them to the beginning of the sequence. Do not change the relative order of the moved cards. For example, if first = 2 and last = 4, an exchange operation on "ABCDEFG" would produce "BCDAEFG".

Perform the specified exchange operation times times on the given sequence and return a String containing the resulting sequence.

Definition

Class:
CardsShuffle
Method:
shuffle
Parameters:
String, int, int, int
Returns:
String
Method signature:
String shuffle(String cards, int first, int last, int times)
(be sure your method is public)

Constraints

  • cards will contain between 1 and 50 characters, inclusive.
  • cards will contain only uppercase letters ('A'-'Z').
  • first will be between 1 and n, inclusive, where n is the number of characters in cards.
  • last will be between first and n, inclusive, where n is the number of characters in cards.
  • times will be between 1 and 100, inclusive.

Examples

  1. "NW"

    2

    2

    9

    Returns: "WN"

    It always moves the second card to the front.

  2. "BMQ"

    1

    2

    2

    Returns: "BMQ"

    This operation does not change anything.

  3. "DARZ"

    1

    3

    5

    Returns: "DARZ"

  4. "KYHID"

    3

    5

    8

    Returns: "YHIDK"

  5. "CDXRJM"

    1

    1

    36

    Returns: "CDXRJM"

  6. "RXSJYBL"

    1

    6

    60

    Returns: "RXSJYBL"

  7. "FSARCBYN"

    5

    5

    74

    Returns: "SARCFBYN"

  8. "YGGXXPKLO"

    8

    9

    63

    Returns: "YGGXXPKLO"

    cards may contain duplicate characters.

  9. "KMCOQHNWNKU"

    9

    10

    9

    Returns: "COQHNWNKKMU"

  10. "WMDKQTBXIXMVT"

    5

    5

    79

    Returns: "MDKQWTBXIXMVT"

  11. "LJPTNSNFWZQFJM"

    1

    4

    11

    Returns: "LJPTNSNFWZQFJM"

  12. "DRRWSOFSBCNUVQH"

    2

    6

    23

    Returns: "ODRRWSFSBCNUVQH"

  13. "SAQXWPQCACEHCHZV"

    4

    14

    76

    Returns: "WPQCACEHCHSAQXZV"

  14. "MLNOZJKPQPXRJXKIT"

    3

    15

    78

    Returns: "KPQPXRJXKMLNOZJIT"

  15. "ACBHHKICQCOENDTOMF"

    7

    12

    48

    Returns: "ACBHHKICQCOENDTOMF"

  16. "DWFCGPXIQVKUYTDLCGD"

    3

    4

    34

    Returns: "DWFCGPXIQVKUYTDLCGD"

  17. "TACIOHORDTQKVWCSGSPQ"

    3

    17

    18

    Returns: "CIOHORDTQKVWCSGTASPQ"

  18. "SBOAGUWNNYQXNZLGDGWPB"

    6

    6

    50

    Returns: "GUSBOAWNNYQXNZLGDGWPB"

  19. "BLNSADEUGUUMOQCDRUBETO"

    7

    13

    38

    Returns: "UGUUMOBLNSADEQCDRUBETO"

  20. "HOACHWDVMXXRDRYXLMNDQTU"

    18

    23

    32

    Returns: "XLMNDQTUHOACHWDVMXXRDRY"

  21. "GMLEJUUKWCIBXUBUMENMEYAT"

    4

    22

    37

    Returns: "MLEJUUKWCIBXUBUMENMEYGAT"

  22. "YDIAJXLOGHIQFMZHLVIHJOUVS"

    3

    3

    11

    Returns: "DIYAJXLOGHIQFMZHLVIHJOUVS"

  23. "YPAYULYEIMUOTEHZRIICFSKPGG"

    2

    11

    76

    Returns: "UYPAYULYEIMOTEHZRIICFSKPGG"

  24. "IPZZRZUCXAMLUDFYKGRUOWZGIOO"

    1

    9

    65

    Returns: "IPZZRZUCXAMLUDFYKGRUOWZGIOO"

  25. "PLEQLWPHAPJNADQHDCNVWDTXJBMY"

    18

    20

    12

    Returns: "LWPHAPJNADQHDCNVPLEQWDTXJBMY"

  26. "HAUXNSPUSGDHIIXQMBFJXJCVUDJSU"

    9

    28

    71

    Returns: "SGDHIIXQMBFJXJCVUDJSHAUXNSPUU"

  27. "YEBMWSIQYOYGYXYMZEVYPZVJEGEBEO"

    10

    13

    24

    Returns: "YOYGYYEBMWSIQXYMZEVYPZVJEGEBEO"

  28. "FTSXDIXTIGSIEEHKCHZDFLILRJQFNXZ"

    18

    22

    93

    Returns: "DFLFTSXDIXTIGSIEEHKCHZILRJQFNXZ"

  29. "SVBSPKYHSENBPPKQTPDDBUOTBBQCWIVR"

    2

    12

    27

    Returns: "SPKYHSENBSVBPPKQTPDDBUOTBBQCWIVR"

  30. "UJJDDNTGEIQVDGAIJVWCYAUBWEWPJVYGE"

    1

    27

    60

    Returns: "UJJDDNTGEIQVDGAIJVWCYAUBWEWPJVYGE"

  31. "XEPBPIWUQZDZUBDUBZVAFSPQPQWUZIFWOV"

    17

    18

    90

    Returns: "XEPBPIWUQZDZUBDUBZVAFSPQPQWUZIFWOV"

  32. "WYVVBURCZMGYJGFDXVTNUNNESLSPLWUIUPF"

    4

    11

    56

    Returns: "VBURCZMGWYVYJGFDXVTNUNNESLSPLWUIUPF"

  33. "BKNHKWPPANLTCFIRJCDDSOZOYVEGURFWCSFM"

    4

    29

    77

    Returns: "UBKNHKWPPANLTCFIRJCDDSOZOYVEGRFWCSFM"

  34. "QMRJOWRGHWLKOBMEAHKGCCNAEHHSVEYMQPXHL"

    18

    35

    59

    Returns: "AEHHSVEYMQPXQMRJOWRGHWLKOBMEAHKGCCNHL"

  35. "NYFDZRHBASJEUYGAFOUBUTPNIMUWFJQSJXVKQD"

    30

    31

    18

    Returns: "UWFJQNYFDZRHBASJEUYGAFOUBUTPNIMSJXVKQD"

  36. "XVRWCTDSNEOGVBPKXLPGDIRBFCRIQIFPGYNKRRE"

    11

    19

    29

    Returns: "TDSNEOGVBPKXLPXVRWCGDIRBFCRIQIFPGYNKRRE"

  37. "NVUCFTPWCTGTWMXNUPYCFGCUQUNUBLMOIITNCKLE"

    9

    36

    77

    Returns: "FTPWCTGTWMXNUPYCFGCUQUNUBLMOIITNNVUCCKLE"


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: