Simple C++ Solution | Hash Table | Greedy
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 
# 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```\nclass Solution {\npublic:\n    int minimumSeconds(vector<int>& nums) {\n        map<int,pair<int,pair<int,int>>>mp;//(max_diff,last_ind,first_ind)\n        for(int i=0;i<nums.size();i++){\n            if(mp.find(nums[i])==mp.end())mp.insert({nums[i],{0,{i,i}}});\n            else {\n                auto it=mp.find(nums[i]);\n                int last_ind=it->second.second.first;\n                int diff=i-last_ind-1;\n                it->second.first=max(it->second.first,diff);\n                it->second.second.first=i;\n\n            }\n        }\n        int ans=1e9;\n        for(auto it=mp.begin();it!=mp.end();it++){\n            int d=it->second.first;\n            int li=it->second.second.first;\n            int fi=it->second.second.second;\n            int len=li-fi+1;\n            int d1=nums.size()-len;\n            d=max(d,d1);\n            if(d%2==0)ans=min(ans,d/2);\n            else if(d%2!=0)ans=min(ans,(d/2)+1);\n        }\n        return ans;\n    }\n};\n```
['Array', 'Hash Table', 'Greedy', 'C++']