<p>You are given a string <code>s</code>. We want to partition the string into as many parts as possible so that each letter appears in at most one part.</p>

<p>Note that the partition is done so that after concatenating all the parts in order, the resultant string should be <code>s</code>.</p>

<p>Return <em>a list of integers representing the size of these parts</em>.</p>

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

<pre>
<strong>Input:</strong> s = &quot;ababcbacadefegdehijhklij&quot;
<strong>Output:</strong> [9,7,8]
<strong>Explanation:</strong>
The partition is &quot;ababcbaca&quot;, &quot;defegde&quot;, &quot;hijhklij&quot;.
This is a partition so that each letter appears in at most one part.
A partition like &quot;ababcbacadefegde&quot;, &quot;hijhklij&quot; is incorrect, because it splits s into less parts.
</pre>

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

<pre>
<strong>Input:</strong> s = &quot;eccbbbbdec&quot;
<strong>Output:</strong> [10]
</pre>

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

<ul>
	<li><code>1 &lt;= s.length &lt;= 500</code></li>
	<li><code>s</code> consists of lowercase English letters.</li>
</ul>

class Solution {

using PII = pair<int, int>;

public:
    vector<int> partitionLabels(string s) {
        vector<vector<int>> letterIntervalArr(26, vector<int>(2, -1));
        for (int i = 0; i < s.size(); i++) {
            int letter = s[i] - 'a';
            if (letterIntervalArr[letter][0] == -1) {
                letterIntervalArr[letter][0] = i;
            }
            letterIntervalArr[letter][1] = i;
        }
        sort(letterIntervalArr.begin(), letterIntervalArr.end());
        int letter = 0;
        while (letterIntervalArr[letter][0] == -1) {
            letter++;
        }
        vector<int> res;
        vector<int> currInterval = letterIntervalArr[letter];
        letter++;
        for (; letter < 26; letter++) {
            if (letterIntervalArr[letter][0] < currInterval[1]) {
                currInterval[1] = max(currInterval[1], letterIntervalArr[letter][1]);
            } else {
                res.push_back(currInterval[1] - currInterval[0] + 1);
                currInterval = letterIntervalArr[letter];
            }
        }
        res.push_back(currInterval[1] - currInterval[0] + 1);
        return res;
    }
};

// Example 1:
// Input: s = "ababcbacadefegdehijhklij"
// Output: [9,7,8]
// Explanation:
// The partition is "ababcbaca", "defegde", "hijhklij".
// This is a partition so that each letter appears in at most one part.
// A partition like "ababcbacadefegde", "hijhklij" is incorrect, because it splits s into less parts.

// Example 2:
// Input: s = "eccbbbbdec"
// Output: [10]


8600