Intutive C++ Solution | Detailed Explanation
Approach\n1. For every element calculate difference between its every two consecutive occurences. \n2. Take maximum of these differences, and call it x.\n3. Try
# Approach\n1. For every element calculate difference between its every two consecutive occurences. \n2. Take maximum of these differences, and call it x.\n3. Try to make every element equal to element with minimum x, call it target. \n4. Keep a set that keeps indices where target occurs and find closest index where target occurs for every element. Maximum of these is our answer. \n# Code\n```\nclass Solution {\npublic:\n    int minimumSeconds(vector<int>& nums) {\n        int n = nums.size();\n        unordered_map<int, int> numFrequency;\n\n        for (int num : nums) {\n            numFrequency[num]++;\n        }\n\n        unordered_map<int, vector<int>> numIndices;\n\n        for (int i = 0; i < n; i++) {\n            numIndices[nums[i]].push_back(i);\n            numIndices[nums[i]].push_back(n + i);\n        }\n        \n        for (auto& [num, indices] : numIndices) {\n            sort(begin(indices), end(indices));\n        }\n        \n        int minTime = INT_MAX;\n        int chosenNum = -1;\n\n        for (auto [num, indices] : numIndices) {\n            int totalIndices = indices.size();\n            int maxInterval = 0;\n            \n            for (int i = 0; i < totalIndices - 1; i++) {\n                int interval = abs(indices[i + 1] - indices[i]);\n                maxInterval = max(maxInterval, interval);\n            }\n            \n            if (maxInterval < minTime) {\n                minTime = maxInterval;\n                chosenNum = num;\n            }\n        }\n\n        set<int> chosenIndices;\n\n        for (int i = 0; i < n; i++) {\n            if (nums[i] == chosenNum) {\n                chosenIndices.insert(i);\n                chosenIndices.insert(n + i);\n                chosenIndices.insert(i - n);\n            }\n        }\n\n        int maxMinTime = 0;\n\n        for (int i = 0; i < n; i++) {\n            if (nums[i] == chosenNum) {\n                continue;\n            }\n            \n            auto it = chosenIndices.upper_bound(i);\n            int rightIndex = *it;\n            int leftIndex = *prev(it);\n            int leftTime = i - leftIndex;\n            int rightTime = rightIndex - i;\n            maxMinTime = max(maxMinTime, min(leftTime, rightTime));\n        }\n\n        return maxMinTime;\n    }\n};\n\n```\n# Time Complexity\n- **Time complexity:**\nO(NlogN) (logN for sorting and set, upper_bound etc)\n\n
['Hash Table', 'C++']