<p>Given a string <code>s</code>, rearrange the characters of <code>s</code> so that any two adjacent characters are not the same.</p>

<p>Return <em>any possible rearrangement of</em> <code>s</code> <em>or return</em> <code>&quot;&quot;</code> <em>if not possible</em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> s = "aab"
<strong>Output:</strong> "aba"
</pre><p><strong class="example">Example 2:</strong></p>
<pre><strong>Input:</strong> s = "aaab"
<strong>Output:</strong> ""
</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 {
public:
    string reorganizeString(string s) {
        
        int hash[256]={0};

        for(int i=0; i<s.size(); i++)
        {
            hash[s[i]]++;
        }

        char max_freq_char;
        int max_freq=INT_MIN;

        for(int i=0; i<s.size(); i++)
        {
            if(max_freq<hash[s[i]])
            {
                max_freq=hash[s[i]];
                max_freq_char=s[i];
            }
        }
          
          int index=0;
         while(index<s.size() && max_freq!=0)
         {
            s[index]=max_freq_char;
            index= index+2;
            max_freq--;

         }

         if(max_freq!=0)
            {
                return "";
            }
          
          hash[max_freq_char]=0;
                   
            
            // for(int i=0; i<s.size(); i++)
            // {
                
            //     while(hash[s[i]]>0)
            //     {
            //          if(index>s.size()-1)
            //            {
            //            index=1;
            //            }
                    
            //     s[index]=s[i];
            //     index=index+2;
            //     hash[s[i]]--;

            //     }
              for (int i = 0; i < 256; i++) {
                while (hash[i] > 0) {
                if (index > s.size()-1)
                 {
                    index = 1; 
                }
                s[index] = i;
                index += 2;
                hash[i]--;
            }
              }
            return s;
    }
};
7800