Beat 100% time complexity 🔥🔥⭐
Approach\nwe hav to see how many number are there in between two sam number and the lenght/2 is the second to change this we have to do fir all the other number
# Approach\nwe hav to see how many number are there in between two sam number and the lenght/2 is the second to change this we have to do fir all the other number minimum of all is answer\n\n# Complexity\n- Time complexity:\nO(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        int ans=n-1;\n\n        //storing the index of each element in inde->vector map\n        for(int i=0;i<n;i++)\n        mp[nums[i]].push_back(i);\n\n        //now simply traverse the map and keep in mind that we require distance/2 amount of time to convert the element in between \n        // exampl: 2 - - - - - 2 so we can chnge other - into 2 in d/2 second \n        //and we to minimize that which element do we have to change it \n        for(auto it:mp){\n            vector<int>temp=it.second;\n            int l=temp.size();\n\n            int eans=(n-1-temp[l-1])+temp[0];\n            //we are not storing the d/2 but only distance becuase we can directly do that at the end of answer \n            for(int i=1;i<l;i++) eans=max(eans,temp[i]-temp[i-1]-1);\n\n            ans=min(ans,eans);\n        }\n         // we add 1 to answer beacuse if the answer if even then by / it by 2 answer wont change but if ans is odd then it will \n         //get shifted to next integer which is the corrcet answer\n         return (ans+1)/2;\n    }\n};\n```
['C++']