Iam_Sandeep

Untitled

Mar 20th, 2026
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.46 KB | None | 0 0
  1. def findMinimumOperations(arr):
  2.     n = len(arr)
  3.    
  4.     # Base case for trivial lengths
  5.     if n <= 1:
  6.         return 0
  7.  
  8.     # 1. Find the index of the element '1'
  9.     idx = arr.index(1)
  10.  
  11.     # 2. Check if the array is an ascending cyclic shift
  12.     is_ascending = (arr[1] == (arr[0] % n) + 1)
  13.  
  14.     # 3. Apply the logic based on the direction
  15.     if is_ascending:
  16.         return min(idx, n - idx + 2)
  17.     else:
  18.         return min(idx + 2, n - idx)
  19.  
  20.  
Advertisement
Add Comment
Please, Sign In to add comment