[C++] || Best Explaination || try all Possibilities || only max gap matters
Intution\nIn this all values can be possibility for target that final vector contains\n// No matters max freq element but matter arrangement or max gap\njust st
**Intution**\nIn this all values can be possibility for target that final vector contains\n// No matters max freq element but matter arrangement or max gap\njust store all indeces for particular element in vector ,USE unordered_map in which every element as key contains a vector as value (key:value in map) of indeces\nex  454871243612\n4 :[0,2,7]\n5 :[1]\n1 :[5,10]\nsimilarly  for all....\nnow you have to traverse on all vectors ;\nTake an example: for 4\'s vector\n[4, , , , , , , , , ,4, , , , , 4, , , ,4, , ]\n a ---------------b---------c-----d---\n a,b,c,d are indeces for 4\n possible ans=(b-a)/2   (b-a  max difference)\njust see the max gap : ) if fill this gap by both sides then in between all gap would have filled\nbecause in 1 sec you can filled or replace the both neighbours of all instances\nfor max gap the amount of second =maxgap/2 (filled by both sides)\njust take glabal minimum\n\n(take care about circularity)\n```\nclass Solution {\npublic:\n    int minimumSeconds(vector<int>& nums) {\n        int n=nums.size();\n        unordered_map<int,vector<int>> valtoind;\n        for(int i=0;i<n;i++)\n        {\n            valtoind[nums[i]].push_back(i);\n        }\n        int ans=INT_MAX;\n        for(auto e:valtoind)\n        {\n            vector<int> temp=e.second;\n            int maxi=0;\n            int s=temp.size();\n            if(s==1) maxi=n/2;\n            \n            for(int i=0;i<s;i++)\n            {\n                maxi=max(maxi,(abs(temp[(i+1)%s]-temp[i]+n)%n)/2);\n            }\n            ans=min(ans,maxi);\n        }\n        return ans;\n    }\n};\n```\nTHANKS FOR UPVOTE
['Greedy', 'C']