✅Easiest 3 Step Cpp / Java / Py / JS Solution | Beginner Level 🏆|  No Advance
\n### C++\n\nclass Solution {\npublic:\n    int minDifference(vector<int>& nums) {\n        //step 1\n        int n = nums.size();\n        if (n <= 4) return 0
\n### C++\n```\nclass Solution {\npublic:\n    int minDifference(vector<int>& nums) {\n        //step 1\n        int n = nums.size();\n        if (n <= 4) return 0;\n\n        // step 2: Sort the array\n        sort(nums.begin(), nums.end());\n\n        // step 3: Evaluate the minimum difference possible with at most 3 moves\n        int minDiff = min({ \n            nums[n-1] - nums[3],      // Change 3 smallest elements\n            nums[n-2] - nums[2],      // Change 2 smallest and 1 largest element\n            nums[n-3] - nums[1],      // Change 1 smallest and 2 largest elements\n            nums[n-4] - nums[0]       // Change 3 largest elements\n        });\n\n        return minDiff;\n    }\n};\n\n```\n### Java\n```\nclass Solution {\n    public int minDifference(int[] nums) {\n        int n = nums.length;\n        if (n <= 4) return 0;\n\n        // Sort the array\n        Arrays.sort(nums);\n\n        // Evaluate the minimum difference possible with at most 3 moves\n        int minDiff = Math.min(\n            Math.min(nums[n - 1] - nums[3], nums[n - 2] - nums[2]),\n            Math.min(nums[n - 3] - nums[1], nums[n - 4] - nums[0])\n        );\n\n        return minDiff;\n    }\n}\n```\n\n### Python3\n```\nclass Solution:\n    def minDifference(self, nums: List[int]) -> int:\n        n = len(nums)\n        if n <= 4:\n            return 0\n\n        # Sort the array\n        nums.sort()\n\n        # Evaluate the minimum difference possible with at most 3 moves\n        min_diff = min(\n            nums[n-1] - nums[3],      # Change 3 smallest elements\n            nums[n-2] - nums[2],      # Change 2 smallest and 1 largest element\n            nums[n-3] - nums[1],      # Change 1 smallest and 2 largest elements\n            nums[n-4] - nums[0]       # Change 3 largest elements\n        )\n\n        return min_diff\n```\n### JavaScript\n```\n/**\n * @param {number[]} nums\n * @return {number}\n */\nvar minDifference = function(nums) {\n    let n = nums.length;\n    if (n <= 4) return 0;\n\n    // Sort the array\n    nums.sort((a, b) => a - b);\n\n    // Evaluate the minimum difference possible with at most 3 moves\n    let minDiff = Math.min(\n        nums[n - 1] - nums[3],      // Change 3 smallest elements\n        nums[n - 2] - nums[2],      // Change 2 smallest and 1 largest element\n        nums[n - 3] - nums[1],      // Change 1 smallest and 2 largest elements\n        nums[n - 4] - nums[0]       // Change 3 largest elements\n    );\n\n    return minDiff;\n};\n\n```\n#### STAY COOL STAY DISCIPLINED..\n\n![image](https://assets.leetcode.com/users/images/ad294515-01e3-4704-a668-9bcc5b0e822c_1717851160.1975598.gif)
['Array', 'Greedy', 'C', 'Sorting', 'Python', 'Java', 'Python3', 'JavaScript']