Splitting a String Into Descending Consecutive Values
MediumBacktracking
Decode it first. Clues, constraints, pattern and plan before any code.Given a string of digits s, decide whether it can be split into two or more non-empty pieces whose numeric values are in descending order and each exactly one less than the piece before. Pieces may have leading zeros ("0090" is the number 90).
"050043" → True ("05", "004", "3" are 5, 4, 3)
"9080701" → False
"10009998" → True ("100", "099", "98")
"1234" → FalseConstraints
1 <= s.length <= 20scontains only digits.