Ctrl K

Smallest Digit Shuffle

Medium
You are given an integer num. Rearrange its digits to get the smallest possible number and return it. The sign stays the same, and the result must not have leading zeros (zero itself is written as just 0).
Example 1
num=5070 → 5007

From the digits 5, 0, 7, 0 without a leading zero, the smallest number is 5007.

Example 2
num=-2093 → -9320

The sign stays negative, and a negative number is smaller the larger its absolute value is: -9320.

Example 3
num=0 → 0
Constraints
  • -10¹⁹ ≤ num ≤ 10¹⁹
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsSorted Parabola Values MediumChain of Multiples MediumMeet at One Value MediumClosest Clock Readings MediumShuffle the Digits Into a Power of Two Medium
loading Python…
Input
num=5070
Expected
5007

Run checks the first 3 tests in your browser. Submit checks all 123 tests on the server, hidden ones included.