cpp sol explained i hindi
Intuition\n Describe your first thoughts on how to solve this problem. \n1. ARRAY LO\n2. COPY KAR KE USI ARRAY KE END MEIN ADD KARDO\n3. NUMBER CHOOSE KARO KONS
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n1. ARRAY LO\n2. COPY KAR KE USI ARRAY KE END MEIN ADD KARDO\n3. NUMBER CHOOSE KARO KONSA LEKE REPLACE KARNA HAI\n4. US NUMBER KA MAXIUM ELEMENTS WALA SECTION DHOONDO\n5. AB HAR EK NUMBER KA MAXIMUM TIME NIKALO EQUALISE KARNE KA-> \n\n        USE MAP- STORE THE LAST INDEX OF THE CURR ELEMENT\n\n        TIME REQUIRED -> I-J/2\n\n        USE ANOTHER MAP TO STORE HE MAX TIME FOR EVERY NUMBER\n\n\n6. SABSE MINIMUN TIME HOGA ANSWER\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nyeh circular array wala question hai\n\nbest practise to use in circular array is to DUPLICATE THE ARRAY AND ADD IT AT THE END OF THE ORIGINAL ARRAY\n\n12345-12345: HERE IF YOU WATCH CAREFULLY, IT MAINTAINS THE CONCEPT OF CIRCULAR ARRAY, LAST ELEMENT KE BAAD FIRSE FIRST ELEMENT A RHA HAI.\n\nNOW WHAT WE HAVE TO DO IS HOW MUCH SECONDS IS REQUIRED TO EQUALISE THE ARRAY:\n\n\nEQUALISE KARNE KE LIE, HUME ARRAY MEIN SE HI NUMBERS CHOOSE KARNA HAI\n\nSO BASICALLY HUMKO YEH FIND OUT KARNA HAI KI KONSA NUMBER SE REPLACE KAR KE EQUALISE KARENGE TO MINIMUM TIME LAG RHA HAI.\n\nFOR EXAMPLE:\n\n2, 1, 3, 4, 2 IS AN ARRAY\n\nSO IF WWE COPY THIS AND ADD AT THE END:\n\n2, 1, 3, 4, 2,, 2, 1, 3, 4, 2\n\nNOW IF I WANT TO CHANGE EVERY ELEMENT TO 2:\nWE NEED 2 SEC WHICH IS BASICALLY N+1/2\n\t\t\t\t\t\t\nPEHLE SECOND MEIN 1 AUR 4 CHANGE HOGA PHIR NEXT SECOND MEIN 3.\n\t\t\t\t\t\t\nAISE AGAR HUM HAR EK ELEMENT KA TIME NIKALE AUR COMPARE KARE TO MINUMUM TIME MIL JAYEGA\n\n**ONE MORE POINT TO NOTE :\n\n**JAB HUM CONVERT KAR RHE HAI, THERE WILL BE MULTIPLE SEGMENTS IN THE ARRAY JAHA HUME CONVERT KARNA HAI\n\n**JAISE 2 * SOME NUMBERS* 2 AGAIN SOME NUMBERS* **\n\n**SO IF FIRST PART TAKES 2 SEC AND SECOND TAKES 4 SEC, SO TOTAL ARRAY WILL BE CONVERTED IN MAX(2, 4) WHICH IS 4 SEC**\n\nAUR JAB NUMBERS CHOOSE KAR RHE HAI, HUME MAXIMUM NUMBERS WALA SEGMENT CHAIYE, MATLAB DO 3 KE BEECH MEIN MAXIMUM ELEMENTS HONE CHAIYE, ISILOYE HUM ARRAY KO COPY KAR RHE HAI.\n\nAB AISE 2 KA NIKALE- JO 2 SEC HUA\n\nBAKI KA NIKALO:\n\n2->>2SEC\n1-> 2SEC\n3->>2SEC\n\nSO THE ANSWER IS MIN(2, 2, 2, 2)= 2\n\n\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```cpp []\nclass Solution {\npublic:\n    int minimumSeconds(vector<int>& nums) {\n        int ans=nums.size();\n        int n= nums.size();\n\n        map<int, int> last;\n\n        //duplicating the original array and adding it to the end of the original arra\n\n        for(int i=0; i<n; i++)\n        {\n            nums.push_back(nums[i]);\n            last[nums[i]]=-1;\n        }\n        n=nums.size(); //because the nums array is extended, so size will be larger than previous\n\n        map<int, int>max_time;\n\n        for(int i=0; i<n; i++)\n        {\n            if(last[nums[i]]!=-1)\n            {\n                int tot_time=(i-last[nums[i]]);\n                tot_time/=2;\n                max_time[nums[i]]=max(max_time[nums[i]], tot_time);\n            }\n            last[nums[i]]=i;\n        }\n\n        for(auto& x : max_time)\n        {\n            ans=min(ans, x.second);\n        }\n\n        return ans;\n        \n    }\n};\n```
['C++']