title: How to rearrange an array in such a way that each element is greater/smaller than its neighbours
body: <p>For example, if the numbers are: </p>
  
  <pre><code>30, 12, 49, 6, 10, 50, 13
  </code></pre>
  
  <p>The array will be:</p>
  
  <pre><code>[10, 6, 30, 12, 49, 13, 50]
  </code></pre>
  
  <p>As you can see:</p>
  
  <ul>
  <li>6 is smaller than both 10 and 30 and </li>
  <li>49 is greater than 12 and 13 and so on.</li>
  </ul>
  
  <p>The numbers are all different and real. I need the most efficient algorithm.</p>