O(n) clear solution - pivot point approach | TypeScript
Approach\nThe approach is just to find the pivot point around which the array is rotated\n(and return -1 if it doesn\'t exist)\n\n# Complexity\n- Time complexit
# Approach\nThe approach is just to find the pivot point around which the array is rotated\n(and return -1 if it doesn\'t exist)\n\n# Complexity\n- Time complexity: O(n)\n- Space complexity: O(1)\n\n# Code\n```typescript\nfunction minimumRightShifts(nums: number[]) {\n  const numsCount = nums.length;\n  let pivot = numsCount;\n\n  for (let i = 1; i < numsCount; i++) {\n    if (nums[i] < nums[i - 1]) {\n      if (pivot !== numsCount) return -1; // can\'t be sorted\n      pivot = i;\n    }\n  }\n\n  if (pivot === numsCount) return 0; // already sorted\n\n  return nums.at(-1)! < nums[0] ? numsCount - pivot : -1;\n}\n```
['TypeScript', 'JavaScript']