<p>Given an array of digits <code>digits</code>, return <em>the largest multiple of <strong>three</strong> that can be formed by concatenating some of the given digits in <strong>any order</strong></em>. If there is no answer return an empty string.</p>

<p>Since the answer may not fit in an integer data type, return the answer as a string. Note that the returning answer must not contain unnecessary leading zeros.</p>

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

<pre>
<strong>Input:</strong> digits = [8,1,9]
<strong>Output:</strong> &quot;981&quot;
</pre>

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

<pre>
<strong>Input:</strong> digits = [8,6,7,1,0]
<strong>Output:</strong> &quot;8760&quot;
</pre>

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

<pre>
<strong>Input:</strong> digits = [1]
<strong>Output:</strong> &quot;&quot;
</pre>

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

<ul>
	<li><code>1 &lt;= digits.length &lt;= 10<sup>4</sup></code></li>
	<li><code>0 &lt;= digits[i] &lt;= 9</code></li>
</ul>

from sortedcontainers import SortedList
class Solution:
    def largestMultipleOfThree(self, digits: List[int]) -> str:
        sortedList = []
        digitSpread = [[] for i in range(3)]
        for i in digits:
            digitSpread[i%3].append(i)
        for i in digitSpread[0]:
            sortedList.append(i)
        pointer1 = 0
        pointer2 = 0
        for l in digitSpread:
            l.sort(reverse=True)
        while pointer1<len(digitSpread[1]) and pointer2<len(digitSpread[2]):
            sortedList.append(digitSpread[1][pointer1])
            sortedList.append(digitSpread[2][pointer2])
            pointer1+=1
            pointer2+=1
        if (len(digitSpread[1])-pointer1)%3==2 and len(digitSpread[2])!=0:
            sortedList.pop()
            sortedList.extend(digitSpread[1][pointer1:pointer1+2])
            pointer1+=2
        if (len(digitSpread[2])-pointer2)%3==2 and len(digitSpread[1])!=0:
            store = sortedList.pop()
            sortedList.pop()
            sortedList.append(store)
            sortedList.extend(digitSpread[2][pointer2:pointer2+2])
            pointer2+=2
        while len(digitSpread[1])-pointer1>2:
            sortedList.extend(digitSpread[1][pointer1:pointer1+3])
            pointer1+=3
        while len(digitSpread[2])-pointer2>2:
            sortedList.extend(digitSpread[2][pointer2:pointer2+3])
            pointer2+=3
        sortedList.sort(reverse=True)
        if sortedList and sortedList[0] == 0:
            return "0"
        strForm = "".join(map(str,sortedList))
        return strForm
        
18200