Well Explained || 2 Approaches || Easy for mind to Accept it
BRUTE APPROACH\n\nclass Solution {\n    public int minDifference(int[] nums) {\n        int n = nums.length;\n        if(n <= 4) return 0;\n        Arrays.sort(
**BRUTE APPROACH**\n```\nclass Solution {\n    public int minDifference(int[] nums) {\n        int n = nums.length;\n        if(n <= 4) return 0;\n        Arrays.sort(nums);\n        int res = Integer.MAX_VALUE;\n        for(int i = 0; i < 4; i++){\n            res = Math.min(res, nums[n - 1 - 3 + i] - nums[i]);\n        }\n        return res;\n    }\n}\n// T.C = O(nlogn) as sorting and loop is constant of 4\n```\nANALYSIS:-\n* **Time Complexity** :- O(NlogN) as sorting and loop is constant of 4\n\n\n* **Space Complexity** :- O(1)\n\n\n**GREEDY APPROACH**\n```\nclass Solution {\n    public int minDifference(int[] nums) {\n        \n        // if the size is smaller than 4 than we can easily make each of them equal and hence min possible difference is zero\n        if(nums.length <= 3) return 0;\n        \n        int n = nums.length;\n        \n        // sort the array in increasing order because we want to consider few of the largest and smallest numbers.\n        Arrays.sort(nums);\n        \n        int res = Integer.MAX_VALUE; // initialize the result with INT_MAX.\n        \n        \n        // Now idea is to try greedy. First of all we must agree that the values \n\t\t// which we will be changing should be either from left end or right end, \n\t\t// As there is no gain if we start changing values from middle of the array. \n\t\t// And hence we can try to make these 3 moves in all following possible \n\t\t// ways and choose the one which gives the best answer. \n        // And because there are only 3 moves so total possibilities will be exactly 4.\n        \n        \n        // CASE 1: when changing only from beg\n        res = Math.min(res, Math.abs(nums[3] - nums[n - 1]));\n        \n        // CASE 2: when change two from beg and one from last\n        res = Math.min(res, Math.abs(nums[2] - nums[n - 2]));\n        \n        // CASE 3: when change only from beg and two from last\n        res = Math.min(res, Math.abs(nums[1] - nums[n - 3]));\n        \n        // CASE 4: when change all the values from last\n        res = Math.min(res, Math.abs(nums[0] - nums[n - 4]));\n        \n        return res;\n    }\n}\n// Time Complexity :- O(NlogN)\n// Space Complexity :- O(1)\n```\nANALYSIS:-\n* **Time Complexity** :- O(NlogN) as sorting\n\n\n* **Space Complexity** :- O(1)
['Java']