TopcoderARCHIVE
Archive/Problems/StringsBetween
SRM · Problem 16397

StringsBetween

Problem statement, definition, constraints, and public examples.

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.
← All problems