LexOrder
TCO19 SRM 750 · 2019-01-09 · by misof
Problem Statement
In this problem, all strings are strings of lowercase English letters ('a'-'z').
You are given the
Below, we define how to compare two strings. This definition is the standard one and we include it just to have a complete, self-contained problem statement. If you already know how string comparison works, you do not have to read it.
Suppose S and T are two distinct strings. We say that S is smaller than T in lexicographic order (denoted S < T) if:
- either S is a proper prefix of T,
- or there is some i >= 0 such that:
- the first i characters of S are the same as the first i characters of T
- the next character of S is smaller than the next character of T
For example:
- "car" < "careful" because "car" is a proper prefix of "careful"
- "dog" < "donut" because the first two characters of both strings are the same ("do") and 'g' is smaller than 'n'.
Notes
- The statements "character x is smaller than character y", "character x is earlier in the alphabet than character y", and "character x has a smaller ASCII code than character y" are equivalent.
- The return value is case-sensitive. The string IMPOSSIBLE must be in all-uppercase.
Constraints
- A will have between 1 and 10 characters, inclusive.
- B will have between 1 and 10 characters, inclusive.
- Each character of A and B will be a lowercase English letter ('a'-'z').
- A will be lexicographically smaller than B.
"car" "dog" Returns: "careful"
Other valid return values include "ceiling", "catastrophiccancellation", "darling", "do", and "dododododo".
"car" "cat" Returns: "cash"
"abcdefghij" "abcdefghik" Returns: "abcdefghijklmnopqrst"
Note that the input strings always have at most 10 characters but the string you return may be longer (up to 50 characters).
"man" "mana" Returns: "IMPOSSIBLE"
"a" "ab" Returns: "aa"
Submissions are judged against all 94 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class LexOrder with a public method string between(string A, string B) · 94 test cases · 2 s / 256 MB per case