ok ^^
time: O(N); space: O(N)\n\n\n\n\nint minimumSeconds(vector<int>& n)\n{\n\tunordered_map<int, int> last, M;\n\tfor(int i{}, sz(size(n)); i<2*sz; ++i)\n\t{\n\t\ti
**time: `O(N)`; space: `O(N)`**\n\n![image](https://assets.leetcode.com/users/images/fbdd36d0-644a-4b19-9b65-edf8a09919d6_1722527790.9847357.png)\n\n```\nint minimumSeconds(vector<int>& n)\n{\n\tunordered_map<int, int> last, M;\n\tfor(int i{}, sz(size(n)); i<2*sz; ++i)\n\t{\n\t\tif(last.count(n[i%sz]))\n\t\t\tM[n[i%sz]] = max(M[n[i%sz]], (i-last[n[i%sz]]-1)%sz);\n\t\tlast[n[i%sz]] = i;\n\t}\n\tint out{INT_MAX};\n\tfor(const auto & [_, x] : M)\n\t\tout = min(out, x);\n\treturn (out+1)/2;\n}\n```
['C', 'C++']