[JavaScript] 2855. Minimum Right Shifts to Sort the Array
---\nBiweekly Contest 113\n- Q1. See below\n- Q2. https://leetcode.com/problems/minimum-array-length-after-pair-removals/solutions/4055165/javascript-2856-minim
---\nBiweekly Contest 113\n- Q1. See below\n- Q2. https://leetcode.com/problems/minimum-array-length-after-pair-removals/solutions/4055165/javascript-2856-minimum-array-length-after-pair-removals/\n\n---\n\n# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n\n```\nvar minimumRightShifts = function (a) {\n  let n = a.length\n  let aSortedStr = [...a].sort((a, b) => a - b).toString()\n\n  if (a.toString() === aSortedStr) return 0\n\n  for (let count = 1; count <= n; count++) {\n    let aRightShifted = []\n    for (let i = 0; i < n; i++) {\n      aRightShifted[(i + 1) % n] = a[i]\n    }\n    if (aRightShifted.toString() === aSortedStr) return count\n    a = aRightShifted\n  }\n\n  return -1\n}\n```\n\n---\n\nBiweekly Contest 113\n- Q1. See above\n- Q2. https://leetcode.com/problems/minimum-array-length-after-pair-removals/solutions/4055165/javascript-2856-minimum-array-length-after-pair-removals/\n\n---\n
['JavaScript']