Problem Statement
A valid string is a string of 0 to L lowercase English letters. All strings in this problem are 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 proper prefix of Y, X is smaller than Y (e.g., "cat" < "cats").
You are given two valid strings A and B. They are not necessarily distinct.
Return any valid string C such that A < C < B. If there is no such C, return "ERROR" instead (quotes for clarity only).
Definition
- Class:
- FindStringBetween
- Method:
- generate
- Parameters:
- int, String, String
- Returns:
- String
- Method signature:
- String generate(int L, String A, String B)
- (be sure your method is public)
Notes
- X is a proper prefix of Y if X is a prefix of Y and X is shorter than Y.
Constraints
- L will be between 1 and 10, inclusive.
- A and B will be valid strings.
Examples
10
"cat"
"elephant"
Returns: "dog"
4
"buzz"
"byte"
Returns: "bye"
7
"buzz"
"byte"
Returns: "buzzard"
4
"pier"
"pies"
Returns: "ERROR"
9
"later"
"earlier"
Returns: "ERROR"