#2160
Minimum Sum of Four Digit Number After Splitting Digits
newbie · 115 · lc easy +12 · verified · 86.3% accepted · 1,505 likes · top 97%
Description
You are given a positive integer num with exactly four digits. Split its digits into two new integers new1 and new2 such that all four digits are used and leading zeros are allowed.
- For example, with num = 2932, you have digits 2, 9, 3, 2. Some possible splits include [22, 93], [23, 92], [223, 9], and [2, 329].
Return the minimum possible value of new1 + new2.
Example 1:
Input: num = 2932
Output: 52
Explanation: Some possible pairs [new1, new2] are [29, 23], [223, 9], etc.
The minimum sum can be obtained by the pair [29, 23]: 29 + 23 = 52.
Example 2:
Input: num = 4009
Output: 13
Explanation: Some possible pairs [new1, new2] are [0, 49], [490, 0], etc.
The minimum sum can be obtained by the pair [4, 9]: 4 + 9 = 13.
Code
1
2
3