Simple O(n) solution | C++ | Unordered Map |
\n\n# Complexity\n- Time complexity: O(n) \n- Space complexity: O(n)\n Add your space complexity here, e.g. O(n) \n\n# Code\n\nclass Solution {\npublic:\n    in
\n\n# Complexity\n- Time complexity: $$O(n)$$ \n- Space complexity: $$O(n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int minimumSeconds(vector<int>& nums) {\n        unordered_map<int,vector<int>>mp;\n        int n=nums.size();\n        for(int i=0;i<n;i++){\n            mp[nums[i]].push_back(i);\n        }\n        int fans=1e9;\n        for(auto &it:mp){\n            vector<int>arr=it.second;\n            int m=arr.size();\n            int ans=(arr[0]+(n-1-arr[m-1])+1)/2;\n            for(int i=1;i<m;i++){\n                ans=max(ans,(arr[i]-arr[i-1])/2);\n            }\n            fans=min(fans,ans);\n        }\n        return fans;\n    }\n};\n```
['C++']