Minimum Sum of Four Digit Number After Splitting Digits - Problem
You are given a positive integer num consisting of exactly four digits. Split num into two new integers new1 and new2 by using the digits found in num. Leading zeros are allowed in new1 and new2, and all the digits found in num must be used.
For example, given num = 2932, you have the following digits: two 2's, one 9 and one 3. Some of the possible pairs [new1, new2] are [22, 93], [23, 92], [223, 9] and [2, 329].
Return the minimum possible sum of new1 and new2.
Input & Output
Example 1 — Basic Case
$
Input:
num = 2932
›
Output:
52
💡 Note:
We can split digits [2,9,3,2]. After sorting: [2,2,3,9]. Optimal split: 23 + 29 = 52
Example 2 — With Leading Zero
$
Input:
num = 4009
›
Output:
13
💡 Note:
Digits are [4,0,0,9]. After sorting: [0,0,4,9]. Optimal split: 04 + 09 = 4 + 9 = 13
Example 3 — All Same Digits
$
Input:
num = 1111
›
Output:
22
💡 Note:
All digits are 1. Any split gives the same result: 11 + 11 = 22
Constraints
- 1000 ≤ num ≤ 9999
Visualization
Tap to expand
Understanding the Visualization
1
Input
4-digit number: 2932
2
Process
Extract digits, sort, and split optimally
3
Output
Minimum possible sum: 52
Key Takeaway
🎯 Key Insight: Sort digits and place smallest ones in tens place to minimize the total sum
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code