Statistics

Problem Statement for "StringsBetween"

Problem Statement

All strings in this problem are strings of 0 to L lowercase English characters. We will call them valid strings.

All string comparisons are standard comparisons according to their lexicographic order: the string with a smaller character at the leftmost index on which they differ is smaller (e.g., "car" < "cat" because 'r' < 't') and if X is a prefix of Y, X is smaller than Y (e.g., "cat" < "cats").

You are given two valid strings A and B such that A < B.

Return the number of valid strings C such that A < C < B.

Definition

Class:
StringsBetween
Method:
count
Parameters:
int, String, String
Returns:
long
Method signature:
long count(int L, String A, String B)
(be sure your method is public)

Constraints

  • L will be between 0 and 10, inclusive.
  • A and B will be valid strings.
  • A will be less than B.

Examples

  1. 1

    ""

    "d"

    Returns: 3

    The valid strings between "" and "d" are "a", "b", and "c".

  2. 2

    "ay"

    "c"

    Returns: 28

    The valid strings are "az", "b", "ba", "bb", ..., "bx", "by", "bz".

  3. 2

    "ay"

    "cb"

    Returns: 30

    Compared to the previous example we now also have valid strings "c" and "ca" within the specified range.

  4. 10

    "bulldog"

    "bulldozers"

    Returns: 350592

  5. 4

    "bx"

    "fad"

    Returns: 57028

  6. 4

    "pier"

    "pies"

    Returns: 0

  7. 10

    ""

    "zzzzzzzzzz"

    Returns: 146813779479509

    The largest possible output.

  8. 10

    "abc"

    "xyzzy"

    Returns: 135069320654491

  9. 4

    "buzz"

    "byte"

    Returns: 2628

  10. 7

    "buzz"

    "byte"

    Returns: 46191134

  11. 9

    "asdag"

    "sdgdsg"

    Returns: 3784953109965

  12. 3

    ""

    "aa"

    Returns: 1

  13. 10

    "dog"

    "dogmatic"

    Returns: 3864446371

  14. 10

    "eweweweway"

    "ewewewewcb"

    Returns: 30

  15. 10

    "azerty"

    "qwerty"

    Returns: 89695400776682

  16. 9

    "b"

    "daycx"

    Returns: 442106476216

  17. 1

    "a"

    "c"

    Returns: 1


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: