Java O(N) solution with max consecutive difference
Approach\nKeep track of all the occurrence of a specific value and then calculate the max difference between the indexes of two consecutive occurrences. the max
# Approach\nKeep track of all the occurrence of a specific value and then calculate the max difference between the indexes of two consecutive occurrences. the max difference by 2 would give the max seconds for a given number.\nMininum of all such values for all the unique values would be the minimum seconds required.\n\n# Complexity\n- Time complexity: O(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(N)\n\n# Code\n```\nclass Solution {\n    public int minimumSeconds(List<Integer> nums) {\n        int size = nums.size();\n        if (size == 1) return 0;\n        Map<Integer, List<Integer>> map = new HashMap<>();\n        for (int i=0; i<size; i++) {\n            int val = nums.get(i);\n            if (!map.containsKey(val)) map.put(val, new ArrayList<>());\n            map.get(val).add(i);\n        }\n        int ans = size;\n        for (List<Integer> list : map.values()) {\n            int maxDiff = (size - list.get(list.size()-1) + list.get(0))/2;\n            for (int i=1; i<list.size(); i++) {\n                int diff = list.get(i) - list.get(i-1);\n                maxDiff = Math.max(maxDiff, diff/2);\n            }\n            ans = Math.min(ans, maxDiff);\n            \n        }\n        return ans;\n    }\n}\n```
['Java']