EASY 'n' QUICK Solution with Approach.
Intuition\n Describe your first thoughts on how to solve this problem. \nIn the end, what will be the number of unique elements in array ?  \n\n# Approach\n Des
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIn the end, what will be the number of unique elements in array ?  \n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nWell idea can be grabbed from intuition itself, you can notice in the end, the array will be of equal elements and that element will be for sure from the array itself. Now *Greedy* approach is to check for each unique number in array, which one gives the **least** **time**, and this can be done in a way, suppose 2 is present at 1st, 5th and 6th positions in an array of size 7 now **[2 , a, b, c, 2, 2, d]** now, each consecutive 2\'s in circulation will help in filling the gap between them and this can be done in **ceil( gap / 2)** time, let\'s store max time between any two consecutive 2\'s , similarly do for all unique numbers in array and return min (max time of any number). Code run in linear time and requires only $$O(n)$$ of extra space for HashMap.\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<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    \n    public int minimumSeconds(List<Integer> al){\n        HashMap<Integer,ArrayList<Integer>> last=new HashMap<>();\n        int i=0;\n        for(int x:al){\n            if(!last.containsKey(x)) {\n                last.put(x, new ArrayList<>());\n            }\n            last.get(x).add(i+1);\n            ++i;\n        }\n        int n=al.size();\n        int min=Integer.MAX_VALUE;\n        for(Map.Entry<Integer,ArrayList<Integer>> en:last.entrySet()){\n            if(en.getValue().size() == 1) {\n                min = Math.min(min,(int)Math.ceil((n-1)/2.0));\n                continue;\n            }\n            int xx=-1;\n            for(i = 0;i<en.getValue().size();i++){\n                int vv=0;\n                if(i==0) {\n                    vv=en.getValue().get(i)-1 + n-en.getValue().get(en.getValue().size()-1);\n                }else {\n                    vv=en.getValue().get(i) - en.getValue().get(i-1)-1;\n                }\n                xx = Math.max(xx,(int)Math.ceil(vv/2.0));\n            }\n            min = Math.min(min,xx);\n        }\n        return min;\n    }\n}\n```
['Java']