 <p>The following contrived examples do not have a unique solution. You need to decide what happens in these cases:</p> <pre><code>0, 1, 2, 3, 4, 5, 6, 7, 8, 9 // first item move to end 2, 1, 3, 4, 5, 6, 7, 8, 9, 0 // adjacent items swapped </code></pre> <p>For all other cases, luckily the telling trait is that the "out-of-order" item will be more than 1 away from <strong><em>both</em></strong> its neighbors (because #2 above).</p> <pre><code>for (i = 0; i &lt; arr.length; i++) { int priorIndex = (i-1) % arr.length; int nextIndex = (i+1) % arr.length; int diffToPriorValue = abs(arr[i] - arr[priorIndex]); int diffToNextValue = abs(arr[i] - arr[nextIndex]); if (diffToPriorValue &gt; arr.length/2) diffToPriorValue = arr.length - diffToPriorValue; // wrap-around if (diffToNextValue &gt; arr.length/2) diffToNextValue = arr.length - diffToNextValue; // wrap-around if (diffToPriorValue != 1 &amp;&amp; diffToNextValue != 1) return i; return -1; </code></pre>