Problem · String
Doing Smart Work
Learn this problemProblem statement
Given a decimal digit string a, perform the following operation any number of times, including zero:
- Swap two adjacent digits only when one digit is even and the other is odd.
Return the smallest string obtainable. Leading zeros are preserved.
Function
getMinimumNumber(a: String) → StringExamples
Example 1
a = "4321"return = "3142"The even digits keep their relative order 4, 2, and the odd digits keep their relative order 3, 1. The smallest valid merge is 3142.
Constraints
1 <= a.length <= 10^5.acontains only decimal digits.