Back to problems

Find minimum operations to make array sorted

Algorithm · IBM · Hard

You are given an integer array a holding n elements. A single move is carried out in the following order: Detach the element currently sitting at the front, call it x, and delete it from the array. Attach x to the back of the array. Walk x from the right end toward the front, exchanging it with the element immediately on its left for as long as that left element is strictly greater than x. Halt the moment x is at position 0 or the element on its left is not greater than x.…

Checking your access…