Maximize Gap || CPP
Steps:\n\n Initialize an empty hash map to track the positions of each number in the array.\n Traverse the input array, updating the hash map with the positions
**Steps:**\n\n* Initialize an empty hash map to track the positions of each number in the array.\n* Traverse the input array, updating the hash map with the positions of each number encountered.\n* For each number in the hash map, compute the maximum gap between consecutive positions by sorting the positions and finding the differences between consecutive elements.\n* Add an additional position to simulate a gap between the first and last positions in the array.\n* Find the smallest maximum gap among all the numbers.\n* Return the smallest maximum gap as the result.\n\n**Time Complexity: O(n)**\n\n**C++**\n```\nclass Solution\n{\n    public:\n        int minimumSeconds(vector<int> &nums)\n        {\n            unordered_map<int, vector < int>> mpp;\n\n            int n = nums.size();\n            for (int i = 0; i < n; i++)\n                mpp[nums[i]].push_back(i);\n\n            int ans = INT_MAX;\n\n            for (auto &it: mpp)\n            {\n                vector<int> pos = it.second;\n                pos.push_back(pos[0] + n);\n\n                int sec = 0;\n                for (int i = 1; i < pos.size(); i++)\n                {\n                    sec = max(sec, (pos[i] - pos[i - 1]) / 2);\n                }\n                ans = min(ans, sec);\n            }\n            return ans;\n        }\n};\n```\n\n
['C++']