Java and C# solutions
Code\njava []\nclass Solution {\n    public int minimumSeconds(List<Integer> nums) {\n        int n = nums.size(), minResult = Integer.MAX_VALUE;\n        HashM
# Code\n```java []\nclass Solution {\n    public int minimumSeconds(List<Integer> nums) {\n        int n = nums.size(), minResult = Integer.MAX_VALUE;\n        HashMap<Integer, List> map = new HashMap<Integer, List>();\n        for(int i=0; i<n; ++i) {\n            int val = nums.get(i);\n            if(!map.containsKey(val)) map.put(val, new ArrayList<Integer>());\n            map.get(val).add(i); \n        }\n        for(Map.Entry<Integer, List> m:map.entrySet()) {\n            int val = m.getKey(), maxCnt = 0;\n            List<Integer> list = m.getValue();\n            int len = list.size();\n            for(int i=1; i<len; ++i) maxCnt = Math.max(maxCnt, list.get(i)-list.get(i-1)-1);\n            maxCnt = Math.max(maxCnt, list.get(0) + n - 1 - list.get(len-1));\n            minResult = Math.min(minResult, maxCnt);\n        }\n        return (minResult+1)/2;\n    }\n}\n\n// Runtime: 70 ms\n```\n``` csharp []\npublic class Solution\n{\n    public int MinimumSeconds(IList<int> nums)\n    {\n        int n = nums.Count, minResult = int.MaxValue;\n        Dictionary<int, IList<int>> map = new Dictionary<int, IList<int>>();\n        for (int i = 0; i < n; ++i)\n        {\n            int val = nums[i];\n            if (!map.ContainsKey(val)) map[val] = new List<int>();\n            map[val].Add(i);\n        }\n        foreach (KeyValuePair<int, IList<int>> m in map)\n        {\n            int val = m.Key, maxCnt = 0;\n            IList<int> list = m.Value;\n            int len = list.Count;\n            for (int i = 1; i < len; ++i) maxCnt = Math.Max(maxCnt, list[i] - list[i-1] - 1);\n            maxCnt = Math.Max(maxCnt, list[0] + n - 1 - list[len-1]);\n            minResult = Math.Min(minResult, maxCnt);\n        }\n        return (minResult + 1) / 2;\n    }\n}\n\n// Runtime: 333 ms\n```\n
['Java']