n boxes with distinct labels: labels[i] is the label of the box at position i (positions are 0-based).
In one step the belt moves: every box travels from position i to position i + 1, and the box at the last position n - 1 moves to position 0.
Return the smallest number of steps after which the labels are strictly increasing from position 0 to position n - 1. If no number of steps achieves that, return -1.
It is guaranteed that if the boxes are not already in ascending order, the label at the last position is smaller than the label at position 0.labels=[7, 9, 2, 4] → 2
After one step: [4, 7, 9, 2]; after the second: [2, 4, 7, 9], ascending.
labels=[3, 8, 12] → 0
The boxes are already in ascending order, so no steps are needed.
labels=[6, 1, 7, 2] → -1
The order breaks in two places (6 > 1 and 7 > 2), and moving the belt never changes the cyclic order of the boxes, so the answer is -1.
labels is not sorted, labels[n - 1] < labels[0]labels=[7, 9, 2, 4]
2
Run checks the first 3 tests in your browser. Submit checks all 100 tests on the server, hidden ones included.