Tap here to switch tabs
Problem
Submissions

Problem: Minimum Operations to Sort a Permutation

Try to solve the Minimum Operations to Sort a Permutation problem.

Statement

You are given an integer array nums of length n, representing a permutation of integers from 00 to n −1- 1.

In one operation, you can perform either of the following actions:

  • Shift the array cyclically to the left by 11 position (the element at index 00 moves to index n −1- 1).

  • Reverse the entire array.

Return the minimum number of operations required to sort nums in ascending order. If it is impossible to sort the array, return −1-1.

Constraints:

  • 1≤1 \leq n ==== nums.length ≤105\leq 10^5

  • 0≤0 \leq nums[i] ≤\leq n −1- 1

  • nums is a permutation of integers from 00 to n −1- 1.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Operations to Sort a Permutation

Try to solve the Minimum Operations to Sort a Permutation problem.

Statement

You are given an integer array nums of length n, representing a permutation of integers from 00 to n −1- 1.

In one operation, you can perform either of the following actions:

  • Shift the array cyclically to the left by 11 position (the element at index 00 moves to index n −1- 1).

  • Reverse the entire array.

Return the minimum number of operations required to sort nums in ascending order. If it is impossible to sort the array, return −1-1.

Constraints:

  • 1≤1 \leq n ==== nums.length ≤105\leq 10^5

  • 0≤0 \leq nums[i] ≤\leq n −1- 1

  • nums is a permutation of integers from 00 to n −1- 1.