simple approach | JAVA
\n\n# Approach\n Describe your approach to solving the problem. \n1. Begin the minDifference method which takes an array of integers as input.\n2. Calculate the
\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Begin the minDifference method which takes an array of integers as input.\n2. Calculate the length of the input array and store it in numsSize.\n3. If the numsSize is less than or equal to 4, return 0 as there are not enough numbers to form a difference.\n4. Sort the input array in ascending order using Arrays.sort(nums).\n5. Initialize a variable minDiff to store the minimum difference as Integer.MAX_VALUE.\n6. Loop through the array from 0 to 3 (inclusive) using the variable left.\n7. Calculate the corresponding right index as numsSize - 4 + left.\n8. Update minDiff by taking the minimum of its current value and the difference between nums[right] and nums[left].\n9. Return the value stored in minDiff.\n\n# Complexity\n- Time complexity:O(n\u22C5logn)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(n) or O(logn)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n\n    public int minDifference(int[] nums) {\n        int numsSize = nums.length;\n        if (numsSize <= 4) return 0;\n\n        Arrays.sort(nums);\n\n        int minDiff = Integer.MAX_VALUE;\n\n        for (int left = 0, right = numsSize - 4; left < 4; left++, right++) {\n            minDiff = Math.min(minDiff, nums[right] - nums[left]);\n        }\n\n        return minDiff;\n    }\n}\n```
['Java']