LeftRightDigitsGame2
SRM 556 · 2012-06-05 · by mystic_tc
Problem Statement
The game is played as follows. First, you place the topmost card (whose digit is the 0-th character of digits) on the table. Then, you pick the cards one-by-one from the top of the deck. For each card, you have to place it either to the left or to the right of all cards that are already on the table.
After all of the cards have been placed on the table, they now form an N-digit number. You are given a
Return the smallest possible value of X you can achieve, as a
Notes
- lowerBound has no leading zeros. This means that any valid number X should also have no leading zeros (since otherwise it will be smaller than lowerBound).
Constraints
- digits will contain between 1 and 50 characters, inclusive.
- Each character of digits will be between '0' and '9', inclusive.
- lowerBound will contain the same number of characters as digits.
- Each character of lowerBound will be between '0' and '9', inclusive.
- The first character of lowerBound will not be '0'.
"565" "556" Returns: "556"
You can achieve exactly 556. The solution is as follows: Place the first card on the table. Place the second card to the right of all cards on the table. Place the last card to the left of all cards on the table.
"565" "566" Returns: "655"
"565" "656" Returns: ""
The largest number you can achieve is 655, but it is still less than 656.
"9876543210" "5565565565" Returns: "5678943210"
"8016352" "1000000" Returns: "1086352"
"9613963206361956826579275983537488795314240324017" "2286079350108094970403342259916655130449482506546" Returns: "2286091693632361956265792759835374887953144034017"
2286091693632361956265792759835374887953144034017
"22283375788952998280235623996945902896551888023210" "15326202222283375788959988359969459028965188802321" Returns: "15326202222283375788959988359969459028965888023210"
15326202222283375788959988359969459028965888023210
"10001011010010110110000101010110110001110111100111" "10101000010010111100111000010100100001111111111100" Returns: "10101000010010111100111000010100100010111111111011"
10101000010010111100111000010100100010111111111011
Submissions are judged against all 154 archived test cases, of which 8 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class LeftRightDigitsGame2 with a public method string minNumber(string digits, string lowerBound) · 154 test cases · 2 s / 256 MB per case