[JavaScript] 2808. Minimum Seconds to Equalize a Circular Array
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n\n\nits all about counting distances between equal elements\n  also from 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n\n```\nits all about counting distances between equal elements\n  also from last to first of equal element\ndo above dor all equal element\n  find max distance for equal equal element\n    divide by half, because we can speard this equal element, on both sides\n      now find min of all these half of max distance\n      this is our answer\n      the time taken to make all equal elements\n```\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---\n\n```\nconst minimumSeconds = function (nums) {\n  const n = nums.length\n  const mapEleToIndexArr = new Map()\n  nums.forEach((e, i) => {\n    if (!mapEleToIndexArr.has(e)) mapEleToIndexArr.set(e, [i])\n    else mapEleToIndexArr.get(e).push(i)\n  })\n  let minTime = Infinity\n  for (const indexArr of mapEleToIndexArr.values()) {\n    const m = indexArr.length\n    let maxDiff = 0\n    for (let i = 1; i < m; i++) {\n      const diff = indexArr[i] - indexArr[i - 1] - 1\n      maxDiff = Math.max(maxDiff, diff)\n    }\n    const lastCircularDiff = n - (indexArr[indexArr.length - 1] - indexArr[0] + 1)\n    maxDiff = Math.max(maxDiff, lastCircularDiff)\n    minTime = Math.min(minTime, Math.ceil(maxDiff / 2))\n  }\n  return minTime\n}\n```\n\n![image.png](https://assets.leetcode.com/users/images/3a5e6f0a-c9b4-4c77-b002-6dae21c87733_1701634573.5520906.png)\n\n---\n
['JavaScript']