title: Find the number of remove-then-append operations needed to sort a given array
body: <p>This is an interview question.  A <code>swap</code> means removing any element from the array and appending it to the back of the same array. Given an array of integers, find the minimum number of <code>swaps</code> needed to sort the array.</p>
  
  <p>Is there a solution better than <code>O(n^2)</code>?</p>
  
  <p>For example:</p>
  
  <p>Input array: [3124].</p>
  
  <p>The number of <code>swaps</code>: 2 ([3124] -> [1243] -> [1234]).</p>