Problem · String

Doing Smart Work

Learn this problem
MediumRubrikOA

Problem 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) → String

Examples

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.
  • a contains only decimal digits.

More Rubrik problems

drafts saved locally
public String getMinimumNumber(String a) {
  // write your code here
}
a"4321"
expected"3142"
checking account