ReconstructNumber
TCO19 SRM 752 · 2019-03-04 · by misof
Problem Statement
You are given the
A positive integer X with n+1 digits (and with no leading zeros) is said to match the given comparisons if all the relations are true for pairs of consecutive digits of X, in order. For example, suppose comparisons is "<<=!". One integer that matches these comparisons is 14770. This is because 1<4, 4<7, 7=7, and 7!=0.
If no (n+1)-digit integer matches all the given comparisons, return an empty
Constraints
- comparisons will have between 0 and 2000 characters, inclusive.
- Each character in comparisons will be one of "<>=!".
">=!<" Returns: "10012"
We have 1 > 0, 0 = 0, 0 != 1, and 1 < 2. There are other numbers that match these comparisons, but this one is the smallest of them all.
"====!====" Returns: "1111100000"
"" Returns: "1"
">>>>>>>>>>>>>>>>>>>>>>>>>>>>>" Returns: ""
"<" Returns: "12"
Submissions are judged against all 91 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class ReconstructNumber with a public method string smallest(string comparisons) · 91 test cases · 2 s / 256 MB per case