<p>You are given an alphanumeric string <code>s</code>. (<strong>Alphanumeric string</strong> is a string consisting of lowercase English letters and digits).</p>

<p>You have to find a permutation of the string where no letter is followed by another letter and no digit is followed by another digit. That is, no two adjacent characters have the same type.</p>

<p>Return <em>the reformatted string</em> or return <strong>an empty string</strong> if it is impossible to reformat the string.</p>

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

<pre>
<strong>Input:</strong> s = &quot;a0b1c2&quot;
<strong>Output:</strong> &quot;0a1b2c&quot;
<strong>Explanation:</strong> No two adjacent characters have the same type in &quot;0a1b2c&quot;. &quot;a0b1c2&quot;, &quot;0a1b2c&quot;, &quot;0c2a1b&quot; are also valid permutations.
</pre>

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

<pre>
<strong>Input:</strong> s = &quot;leetcode&quot;
<strong>Output:</strong> &quot;&quot;
<strong>Explanation:</strong> &quot;leetcode&quot; has only characters so we cannot separate them by digits.
</pre>

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

<pre>
<strong>Input:</strong> s = &quot;1229857369&quot;
<strong>Output:</strong> &quot;&quot;
<strong>Explanation:</strong> &quot;1229857369&quot; has only digits so we cannot separate them by characters.
</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 only lowercase English letters and/or digits.</li>
</ul>

class Solution {
public:
    string reformat(string s) {
        if(s.size() <= 2){
            if(s.size() == 1) return s;
            int ans = 0;
            if(isalpha(s[0])) ans += 1;
            if(isalpha(s[1])) ans += 1;
            if(ans == 1) return s;
            return "";
        }
        vector<vector<int>> v (2);
        for(int i = 0; i < s.size(); i++){
            if(isalpha(s[i])){
                v[0].push_back(i);
            }else v[1].push_back(i);
        }
        if(v[0].size() < v[1].size() - 1 || v[0].size() > v[1].size() + 1) return "";

        int l = 0, r = 0;
        string res = "";
        if(v[0].size() >= v[1].size()){
            while(l < v[0].size() && r < v[1].size()){
                res += s[v[0][l]];
                res += s[v[1][r]];
                l += 1;
                r += 1;
            }
            while(l < v[0].size()){
                res += s[v[0][l]];
                l += 1;
            }
        }else{
            while(l < v[0].size() && r < v[1].size()){
                res += s[v[1][r]];
                res += s[v[0][l]];
                l += 1;
                r += 1;
            }
            while(r < v[1].size()){
                res += s[v[1][r]];
                r += 1;
            }
        }
        return res;
    }
};
10500