Solution for Leetcode#1509
\n\n# Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \nStep-01: At first
![image.png](https://assets.leetcode.com/users/images/f24de383-3c4d-4dfa-81b0-b2dff6fd6acf_1719982788.297745.png)\n\n# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nStep-01: At first, need to sort the arrray\nStep-02: Follow the below four options how 3 moves are done\nStep-03: Find the minimum difference among all options\n\n![image.png](https://assets.leetcode.com/users/images/09575139-b495-4344-8526-8893511bacc1_1719982958.9735334.png)\n\n\n# Complexity\n- Time complexity: O(nLog(n))\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n\nCoding Option-01:  (Using **JAVA**)\n```\nclass Solution {\n    public int minDifference(int[] nums) {\n        int n=nums.length;\n        if(n<=3){\n            return 0;\n        }        \n        Arrays.sort(nums);\n                \n        int result=Integer.MAX_VALUE;\n\n        result=Math.min(result, nums[n-4] - nums[0]);\n        result=Math.min(result, nums[n-3] - nums[1]);\n        result=Math.min(result, nums[n-2] - nums[2]);\n        result=Math.min(result, nums[n-1] - nums[3]);\n    \n        return result; \n    }\n\n}\n```\n\nCoding Option-02:  (Using **JAVA**)\n```\nclass Solution {\n    public int minDifference(int[] nums) {\n        int n=nums.length;\n        if(n<=3){\n            return 0;\n        }        \n        Arrays.sort(nums);       \n        \n        int result=Integer.MAX_VALUE;\n\n        for(int i=0; i<4; i++){\n                result = Math.min( result, nums[n-(4-i)]-nums[i] );\n        }\n\n        return result;\n    }\n\n}\n```
['Java']