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
""
"d"
Returns: 3
The valid strings between "" and "d" are "a", "b", and "c".
2
"ay"
"c"
Returns: 28
The valid strings are "az", "b", "ba", "bb", ..., "bx", "by", "bz".
2
"ay"
"cb"
Returns: 30
Compared to the previous example we now also have valid strings "c" and "ca" within the specified range.
10
"bulldog"
"bulldozers"
Returns: 350592
4
"bx"
"fad"
Returns: 57028
4
"pier"
"pies"
Returns: 0
10
""
"zzzzzzzzzz"
Returns: 146813779479509
The largest possible output.
10
"abc"
"xyzzy"
Returns: 135069320654491
4
"buzz"
"byte"
Returns: 2628
7
"buzz"
"byte"
Returns: 46191134
9
"asdag"
"sdgdsg"
Returns: 3784953109965
3
""
"aa"
Returns: 1
10
"dog"
"dogmatic"
Returns: 3864446371
10
"eweweweway"
"ewewewewcb"
Returns: 30
10
"azerty"
"qwerty"
Returns: 89695400776682
9
"b"
"daycx"
Returns: 442106476216
1
"a"
"c"
Returns: 1