Minimum Sum of Four Digit Number After Splitting Digits - Problem
Minimum Sum After Digit Redistribution

Imagine you have a 4-digit number and you need to redistribute its digits to create two new numbers that give you the smallest possible sum.

๐ŸŽฏ Your Mission: Given a positive integer num with exactly 4 digits, split all its digits to form two new integers new1 and new2. Your goal is to minimize new1 + new2.

๐Ÿ“ Rules:
โ€ข You must use all four digits from the original number
โ€ข Leading zeros are allowed (so digits can be distributed freely)
โ€ข Each new number must have at least one digit

๐Ÿ’ก Example: For num = 2932
Available digits: [2, 9, 3, 2]
Possible splits: [22, 93], [23, 92], [29, 32], [2, 932], etc.
The optimal split minimizes the sum!

Input & Output

example_1.py โ€” Basic Case
$ Input: num = 2932
โ€บ Output: 52
๐Ÿ’ก Note: Digits are [2,9,3,2]. After sorting: [2,2,3,9]. Optimal split: new1 = 2*10 + 3 = 23, new2 = 2*10 + 9 = 29. Sum = 23 + 29 = 52.
example_2.py โ€” All Same Digits
$ Input: num = 4009
โ€บ Output: 13
๐Ÿ’ก Note: Digits are [4,0,0,9]. After sorting: [0,0,4,9]. Optimal split: new1 = 0*10 + 4 = 4, new2 = 0*10 + 9 = 9. Sum = 4 + 9 = 13.
example_3.py โ€” Ascending Order
$ Input: num = 1234
โ€บ Output: 37
๐Ÿ’ก Note: Digits are [1,2,3,4]. Already sorted. Optimal split: new1 = 1*10 + 3 = 13, new2 = 2*10 + 4 = 24. Sum = 13 + 24 = 37.

Visualization

Tap to expand
Card Distribution Game: Minimize Total ScoreGoal: Split 4 digit-cards between 2 players to get minimum total scoreInitial Cards: 29322932After Sorting: [2,2,3,9]2239Player 12TENSร—103ONESร—1Score: 23Player 22TENSร—109ONESร—1Score: 29Total Score: 52(Minimum Possible!)
Understanding the Visualization
1
Sort Your Cards
Arrange the 4 digit cards in ascending order
2
Strategic Placement
Give the smallest cards the 'tens' position (higher weight)
3
Fill Remaining
Place larger cards in 'ones' positions
4
Calculate Score
Sum both hands for minimum total
Key Takeaway
๐ŸŽฏ Key Insight: Always put the smallest digits in the tens places to minimize both numbers simultaneously!

Time & Space Complexity

Time Complexity
โฑ๏ธ
O(1)

Fixed 4 digits means constant number of combinations (about 2^4 = 16 ways)

n
2n
โœ“ Linear Growth
Space Complexity
O(1)

Only storing digits and minimum sum, no additional data structures

n
2n
โœ“ Linear Space

Constraints

  • 1000 โ‰ค num โ‰ค 9999
  • num consists of exactly 4 digits
  • Leading zeros are allowed in the resulting numbers
Asked in
Google 15 Amazon 12 Meta 8 Microsoft 6
18.4K Views
Medium Frequency
~8 min Avg. Time
892 Likes
Ln 1, Col 1
Smart Actions
๐Ÿ’ก Explanation
AI Ready
๐Ÿ’ก Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen