Split With Minimum Sum - Problem
Given a positive integer num, split it into two non-negative integers num1 and num2 such that:
- The concatenation of
num1andnum2is a permutation ofnum. - In other words, the sum of the number of occurrences of each digit in
num1andnum2is equal to the number of occurrences of that digit innum. num1andnum2can contain leading zeros.
Return the minimum possible sum of num1 and num2.
Input & Output
Example 1 — Basic Case
$
Input:
num = 4325
›
Output:
59
💡 Note:
Split digits [4,3,2,5] → sort to [2,3,4,5] → alternate assignment: num1=24, num2=35 → sum = 24 + 35 = 59
Example 2 — Two Digits
$
Input:
num = 687
›
Output:
75
💡 Note:
Split digits [6,8,7] → sort to [6,7,8] → alternate: num1=68, num2=7 → sum = 68 + 7 = 75
Example 3 — With Zeros
$
Input:
num = 1000
›
Output:
10
💡 Note:
Split digits [1,0,0,0] → already sorted → alternate: num1=10, num2=00 → sum = 10 + 0 = 10
Constraints
- 10 ≤ num ≤ 109
- num does not contain leading zeros
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code