<p>Given a positive integer <code>num</code>, split it into two non-negative integers <code>num1</code> and <code>num2</code> such that:</p>

<ul>
	<li>The concatenation of <code>num1</code> and <code>num2</code> is a permutation of <code>num</code>.

	<ul>
		<li>In other words, the sum of the number of occurrences of each digit in <code>num1</code> and <code>num2</code> is equal to the number of occurrences of that digit in <code>num</code>.</li>
	</ul>
	</li>
	<li><code>num1</code> and <code>num2</code> can contain leading zeros.</li>
</ul>

<p>Return <em>the <strong>minimum</strong> possible sum of</em> <code>num1</code> <em>and</em> <code>num2</code>.</p>

<p><strong>Notes:</strong></p>

<ul>
	<li>It is guaranteed that <code>num</code> does not contain any leading zeros.</li>
	<li>The order of occurrence of the digits in <code>num1</code> and <code>num2</code> may differ from the order of occurrence of <code>num</code>.</li>
</ul>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> num = 4325
<strong>Output:</strong> 59
<strong>Explanation:</strong> We can split 4325 so that <code>num1</code> is 24 and <code>num2</code> is 35, giving a sum of 59. We can prove that 59 is indeed the minimal possible sum.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> num = 687
<strong>Output:</strong> 75
<strong>Explanation:</strong> We can split 687 so that <code>num1</code> is 68 and <code>num2</code> is 7, which would give an optimal sum of 75.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>10 &lt;= num &lt;= 10<sup>9</sup></code></li>
</ul>

class Solution:
    def splitNum(self, num: int) -> int:
        digits = sorted(str(num), reverse=True)
        l = len(digits)
        n1 = "".join(digits[2*i] for i in range(l//2 + l%2))[::-1]
        n2 = "".join(digits[2*i+1] for i in range(l//2))[::-1]
        n1 = '0' if n1=="" else n1
        n2 = '0' if n2=="" else n2
        return int(n1)+int(n2)


"""

Okay so we'll need a string form of num
and a map from each digit to num occurance

How can we form the smallest sum?

if you dont make the lengths at most off by 1 then one will
be longer in the total sum, which could only increase. Is that always a bad thing?

I think you want to sort the digits. Then effectively you can take pairs from poping the tail
and this will be the sum no matter what. The sum of those will be what you want.
Conversely you could form them by a reverse sort then take evens and odds and sum them.

99999
99
v.s.
999
9999

Yes, if the digits are sorted, I think so.


"""
        
29