😊 Made it Easy with explainations ✅✅ | Greedy -> Hashmap
Intuition\n Describe your first thoughts on how to solve this problem. \n So given question asks to make the cyclic array equal to any of its elements\n and the
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n So given question asks to make the cyclic array equal to any of its elements\n and the conditions are you can only convert a number to its neigbour\n for eg. nums[i] can be -> nums[i], nums[i-1], nums[i+1] \n and return the minm time doing so.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n     \n* so the first approach which comes in our mind is to find the maxm occured element \n     and then convert the all other element into it greedly\n     It might seem appropriate from given example test cases \n     but what if there are more than 1 element which has equal maxm frequency \n      1. now you might think choose any one it will be same , well in reality its not\n      2. Now lets test with another test case \n     [1,11,11,11,19,12,8,7,19] , dry run it yourself once\n     you will find that converting all to 11 will take 3 sec\n     lets try again with 19 \n     it takes only 2 sec and 19 is not even maxm occured element \n     it means greedy approach has not one but 2 errors and will not work here\n    ### Solution Using HashMap\n    what if we check each element and  time it will take \n     to convert all array elements equal to it\n    and return the minm time lets understand How\n    we will find the every indexes of an element \n    and will see how much time will its all copies will take\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\n    int minimumSeconds(vector<int>& nums) {\n        int n=nums.size();\n        // map to store all indexes of an element\n        unordered_map<int,vector<int>>umap;\n        for(int i=0;i<n;i++){\n            umap[nums[i]].push_back(i);\n        }\n        int ans=1e7;\n        for(auto &[num,pos] :umap){\n        //lets make a relation between last and first index to find the diffrence between them\n            pos.push_back(pos[0]+n);\n            int time=0;\n            for(int i=1;i<pos.size();i++){\n       // now lets find the diffrence between 2 copies of it \n                int diff=pos[i]-pos[i-1];\n                // we know that both copies will try to make its neighbour equal \n                // means the diff will reduce by power of 2 and the currTime to fill their gap is\n                int currTime=diff/2;\n    // total time taken will be maxm time taken to fill any gap\n                time=max(currTime,time);\n            }\n            ans=min(time,ans);\n        }\n        return ans;\n    }\n};\n```
['Hash Table', 'Greedy', 'C++']