Mid/SeniorMathSorting

Smallest Value of the Rearranged Number

You are given an integer num. Rearrange the digits of num such that its value is minimized and it does not contain any leading zeros.

Return the rearranged number with minimal value.

Note that the sign of the number does not change after rearranging the digits.

Example 1
Inputnum = 310
Output103
The arrangement with the smallest value that does not contain any leading zeros is 103.
Example 2
Inputnum = -7605
Output-7650
The arrangement with the smallest value that does not contain any leading zeros is -7650.

Constraints

  • -10^15 <= num <= 10^15

Asked at 2 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate