Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Split With Minimum Sum

XPChallenge Points: 10
levelLevel: Easy

You are given a positive integer num. You need to divide its digits into two new integers numA and numB such that:

  • The digits used in numA and numB together are exactly the digits in num.

  • The order of digits can be rearranged.

  • Leading zeros are allowed in the resulting numbers.

Your goal is to make the sum numA + numB as small as possible.

Example 1:

Input: num = 5051

Output: 56

Explanation:

Possible digit rearrangement → digits: [0,0,5,1] We can create: numA = 05 → 5 numB = 10 → 10 Sum = 15 (but rearranging for minimum gives) → numA = 50, numB = 6 → 56

Example 2:

Input: num = 9812

Output: 110

Explanation:

Sorted digits → [1,2,8,9] Split into two small formed numbers: numA = 19 numB = 28 Sum = 47 (minimal is achieved by this balancing)

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result