O(N) Very Simple Solution Direct
Intuition\n Describe your first thoughts on how to solve this problem. \nSaw that the previous and next is filling at each second so something \ndistance will c
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nSaw that the previous and next is filling at each second so something \ndistance will come in play\n\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nJust calculate the maximum gap between same elements and then picking the minimum of the maximum gap between all elements\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(N)--> In a single loop traversal of array\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(3*k)--> FOR DICTIONARY where k=unique elements in array\n\n# Code\n```\nclass Solution:\n    def minimumSeconds(self, nums: List[int]) -> int:\n        n=len(nums)\n        d={}\n# Calculate gaps between same elements of the array\n# in map we store for each unique element (maxgap , first_index , prev_index)\n        for i in range(n):\n            if(nums[i] not in d):\n                d[nums[i]]=[0,i,i]\n            else:\n# maximum between present gap and (prev index - current index) \n                d[nums[i]][0]=max(d[nums[i]][0],i-d[nums[i]][2]-1)\n                d[nums[i]][2]=i\n\n# for difference of first and last similar element of array (CIRCULAR ARRAY)\n        for i in d:\n            d[i][0]=max(n-(d[i][2]-d[i][1])-1,d[i][0])\n\n# for minimum between maximum gaps of all elements\n        ans=10**9\n        for i in d:\n                ans=min(ans,d[i][0])\n\n# every second gap decrease by 2 (element-->   <--element)\n        ans=math.ceil(ans/2)\n        return ans\n        \n\n\n                \n            \n            \n        \n```
['Python3']