🔥|| Beats 100% || Java & Python Solution || Explained || ✅🔥
Intuition - \nThe problem can be solved using a frequency map to keep track of indices where each number appears in the nums list. For each number, we find the 
# Intuition - \nThe problem can be solved using a frequency map to keep track of indices where each number appears in the `nums` list. For each number, we find the maximum distance between two indices where it appears and calculate the time needed to make all elements equal, considering the time taken to traverse this maximum distance.\n\n# Approach - \n- Create a frequency map to store the indices of each number in the `nums` list.\n- For each number, find the maximum distance between two indices where it appears and calculate the time needed to traverse this maximum distance.\n- Update the result with the minimum time calculated for each number.\n\n# Complexity - \n- Time complexity: O(n), where n is the size of the `nums` list. We traverse the list once to create the frequency map and then calculate the maximum distance and time for each number.\n- Space complexity: O(n), where n is the size of the `nums` list. We use a frequency map to store indices, which can have at most n entries.\n\nThe code provided implements the above approach to find the minimum time needed to make all elements in the list equal and returns the result.\n\n# Code\n``` Java []\nclass Solution {\n    public int minimumSeconds(List<Integer> nums) {\n        Map<Integer, List<Integer>> frequencyMap = new HashMap<>();\n        for (int i = 0; i < nums.size(); i++) {\n            int num = nums.get(i);\n            frequencyMap.putIfAbsent(num, new ArrayList<>());\n            frequencyMap.get(num).add(i);\n        }\n\n        int result = Integer.MAX_VALUE;\n        for (List<Integer> indices : frequencyMap.values()) {\n            int maxDistance = indices.get(0) + nums.size() - indices.get(indices.size() - 1) - 1;\n            for (int i = 0; i < indices.size() - 1; i++) {\n                int diffIndex = indices.get(i + 1) - indices.get(i) - 1;\n                maxDistance = Math.max(maxDistance, diffIndex);\n            }\n            maxDistance = (int) Math.ceil((double) maxDistance / 2);\n            result = Math.min(result, maxDistance);\n        }\n        return result;\n    }\n}\n\n```\n\n\n``` Python []\nfrom collections import defaultdict\n\nclass Solution:\n    def minimumSeconds(self, nums):\n        frequencyMap = defaultdict(list)\n        for i, num in enumerate(nums):\n            frequencyMap[num].append(i)\n\n        result = float(\'inf\')\n        for indices in frequencyMap.values():\n            maxDistance = indices[0] + len(nums) - indices[-1] - 1\n            for i in range(len(indices) - 1):\n                diffIndex = indices[i + 1] - indices[i] - 1\n                maxDistance = max(maxDistance, diffIndex)\n            maxDistance = (maxDistance + 1) // 2\n            result = min(result, maxDistance)\n\n        return result\n\n\n```
['Java']