Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def findMinimumOperations(arr):
- n = len(arr)
- # Base case for trivial lengths
- if n <= 1:
- return 0
- # 1. Find the index of the element '1'
- idx = arr.index(1)
- # 2. Check if the array is an ascending cyclic shift
- is_ascending = (arr[1] == (arr[0] % n) + 1)
- # 3. Apply the logic based on the direction
- if is_ascending:
- return min(idx, n - idx + 2)
- else:
- return min(idx + 2, n - idx)
Advertisement
Add Comment
Please, Sign In to add comment