Video Explanation (Optimizing the brute force solution N^3 --> N^2 --> N)
Explanation\n\nClick here for the video link\n\n# Code\n\nclass Solution {\npublic:\n    int minimumSeconds(vector<int>& nums) {\n        unordered_map<int, vec
# Explanation\n\n[Click here for the video link](https://youtu.be/lmDfqaqxpwU)\n\n# Code\n```\nclass Solution {\npublic:\n    int minimumSeconds(vector<int>& nums) {\n        unordered_map<int, vector<int>> indexes;\n        \n        int n = nums.size();\n        int min_dist = n-1;\n        \n        for (int j = 0; j < n; j ++) \n            indexes[nums[j]].push_back(j);\n        \n        for (auto i : indexes) {\n            vector<int> pos = i.second;\n            \n            int len = pos.size();\n            int max_dist = (n - 1 - pos[len-1]) + pos[0];\n            \n            for (int j = 1; j < len; j ++) {\n                max_dist = max (max_dist, pos[j] - pos[j-1] - 1);\n            }\n            \n            min_dist = min(min_dist, max_dist);\n        }\n        \n        return (min_dist + 1) / 2;\n    }\n};\n```
['C++']