title: How to shuffle a character array with no two duplicates next to each other?
body: <p>I was asked this question in an interview:</p>
  
  <blockquote>
    <p>How to shuffle a character array with no two duplicates next to each other?</p>
  </blockquote>
  
  <p>The algorithm I came up with was :</p>
  
  <ol>
  <li>have a <code>HashMap</code> of Character, count of occurrence of Character pairs.
  With this find the count of duplicate vs unique elements.</li>
  <li>If duplicate > unique, cannot form a shuffled array with no 2
  duplicate elements next to each other (?)</li>
  <li>if unique >= duplicate, have 2 stacks - 1 containing unique
  characters and one containing duplicate characters. Construct the
  resulting array in such a way that pop an element from unique stack
  first and pop an element from duplicate stack next. Repeat</li>
  </ol>
  
  <p>For example:</p>
  
  <pre><code>[a,b,b,c] shuffled array with above algorithm - [a,b,c,b];
  
  [b,b,b,c] unique &lt; duplicate return error
  </code></pre>
  
  <p>But I am pretty sure I am overcomplicating the logic. Is there an easier and fool proof way to do this?</p>