Python O(n) solution explained [600 ms]
Approach\nTime to change the whole list nums of length n to a particular num from nums is equal to:\n - n//2 if num does not have duplicates\n - (max difference
# Approach\nTime to change the whole list `nums` of length `n` to a particular `num` from `nums` is equal to:\n - `n//2` if `num` does not have duplicates\n - (max difference between adjacent indeces of `num` duplicates) // 2\n\nFor example, for `nums = [1, 7, 9, 5, 1]`, the time to flood `nums` with `1`\'s is `(4 - 0)//2 = 2`. To take into account that array is circular, we initialize `max_dist` for a selected `num` with `(1st index of num) + n - (last index of num)`.\n\nEvidently, for each distinct `num` in `nums` we need:\na) to have the list of its indeces (i.e., create dictionary `num2idx` mapping `num` to the list of its indeces)\nb) to find the max distance between adjacent indeces of this `num`\n\nSelect minimum of `max_dist` over each distinct `num` in `nums` as an the answer `ans` and return `ans//2`\n\n\n# Complexity\n- Time complexity: `O(n)`\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: `O(n)`\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n``` python\nclass Solution:\n    def minimumSeconds(self, nums: List[int]) -> int:\n        num2idx: DefaultDict[int, List[int]] = defaultdict(list)\n        for i, num in enumerate(nums):\n            num2idx[num].append(i)\n\n        ans = len(nums)\n        for key in num2idx:\n            if len(num2idx[key]) == 1:\n                continue\n            \n            max_dist = num2idx[key][0] + len(nums) - num2idx[key][-1]\n            for i in range(len(num2idx[key]) - 1):\n                max_dist = max(max_dist, (num2idx[key][i+1] - num2idx[key][i]))\n\n            ans = min(ans, max_dist)\n        return ans//2\n    # end minimumSeconds()\n```
['Python3']