Statistics

Problem Statement for "TheLuckyString"

Problem Statement

John and Brus are studying string theory at the university. According to Brus, a string is called lucky if no two consecutive characters are equal. John is analyzing a String s, and he wants to know how many distinct lucky strings can be generated by reordering the letters in s. If s is a lucky string in its original ordering, it should also be considered in the count.

Definition

Class:
TheLuckyString
Method:
count
Parameters:
String
Returns:
int
Method signature:
int count(String s)
(be sure your method is public)

Constraints

  • s will contain between 1 and 10 characters, inclusive.
  • Each character of s will be a lowercase letter ('a' - 'z').

Examples

  1. "ab"

    Returns: 2

    Two lucky strings - "ab" and "ba".

  2. "aaab"

    Returns: 0

    It's impossible to construct a lucky string.

  3. "aabbbaa"

    Returns: 1

    "abababa" is the only lucky string that can be generated.

  4. "abcdefghij"

    Returns: 3628800

  5. "zzddvveett"

    Returns: 39480

  6. "nhhhhhalrn"

    Returns: 336

  7. "g"

    Returns: 1

  8. "kavkvkkak"

    Returns: 6

  9. "asdfgasdf"

    Returns: 8760

  10. "aaaabbc"

    Returns: 3

  11. "zzzzzzzz"

    Returns: 0

  12. "zzz"

    Returns: 0

  13. "zzzzzzz"

    Returns: 0

  14. "wwwwwwwwww"

    Returns: 0

  15. "higihgiigg"

    Returns: 138

  16. "hghgggiggg"

    Returns: 0

  17. "gihggghigg"

    Returns: 0

  18. "hggigggggi"

    Returns: 0

  19. "giiggggggg"

    Returns: 0

  20. "iggggghgii"

    Returns: 0

  21. "hggighigii"

    Returns: 138

  22. "xxxxyyyxxx"

    Returns: 0

  23. "xxxxxxyxy"

    Returns: 0

  24. "xyxxxyyxx"

    Returns: 0

  25. "xxxxxxxxy"

    Returns: 0

  26. "xxxxxxxyy"

    Returns: 0

  27. "xxxyxxyxx"

    Returns: 0

  28. "ageifhbace"

    Returns: 584640

  29. "egaciidadg"

    Returns: 96480

  30. "beieddcaai"

    Returns: 96480

  31. "caaagehgag"

    Returns: 2520

  32. "giggjfcaci"

    Returns: 47760

  33. "aabbbccdaa"

    Returns: 1074

  34. "abcdzefghz"

    Returns: 1451520

  35. "abcdeababa"

    Returns: 2520

  36. "abcdefghia"

    Returns: 1451520

  37. "ba"

    Returns: 2

  38. "dihgfejcba"

    Returns: 3628800

  39. "edcba"

    Returns: 120

  40. "iabcdefghi"

    Returns: 1451520

  41. "gkeababzea"

    Returns: 47760

  42. "acab"

    Returns: 6

  43. "asdfasaada"

    Returns: 156

  44. "dsasdaa"

    Returns: 38

  45. "cba"

    Returns: 6

  46. "htjkhgdea"

    Returns: 141120

  47. "jidefghabc"

    Returns: 3628800

  48. "bba"

    Returns: 1

  49. "aaaaaaaaaa"

    Returns: 0

  50. "bca"

    Returns: 6

  51. "dcba"

    Returns: 24

  52. "aabbccddee"

    Returns: 39480

  53. "dsdab"

    Returns: 36

  54. "zzcba"

    Returns: 36

  55. "fedcba"

    Returns: 720

  56. "aaallacca"

    Returns: 6

  57. "jihgfedcba"

    Returns: 3628800

  58. "abcdefgefg"

    Returns: 236880

  59. "abcabcabcd"

    Returns: 2184

  60. "cdefghijkl"

    Returns: 3628800

  61. "abcdafghij"

    Returns: 1451520

  62. "sasa"

    Returns: 2

  63. "asdgasdgsd"

    Returns: 4204

  64. "aacdefghij"

    Returns: 1451520

  65. "zycdefghvd"

    Returns: 1451520

  66. "dbca"

    Returns: 24

  67. "aaabbbcccd"

    Returns: 2184

  68. "dteyuvvbi"

    Returns: 141120

  69. "jabcdefghi"

    Returns: 3628800

  70. "abcddsdfgf"

    Returns: 115920

  71. "abcdbfgccj"

    Returns: 115920

  72. "zyxcba"

    Returns: 720

  73. "abcdefgefh"

    Returns: 584640

  74. "abcdedrtkb"

    Returns: 584640

  75. "gituoib"

    Returns: 1800

  76. "gituoibyh"

    Returns: 141120

  77. "abaahijklb"

    Returns: 115920

  78. "aabcdefghi"

    Returns: 1451520

  79. "aaabbbccde"

    Returns: 10080

  80. "aaaabbcccc"

    Returns: 138

  81. "aabc"

    Returns: 6

  82. "dca"

    Returns: 6

  83. "abcdefghhh"

    Returns: 282240

  84. "uuvvkklll"

    Returns: 1686


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: