JAVA Solution Explained in HINDI(2 Approaches)
https://youtu.be/eb4vwq4BBxI\n\nFor explanation, please watch the above video and do like, share and subscribe the channel. \u2764\uFE0F Also, please do upvote 
https://youtu.be/eb4vwq4BBxI\n\nFor explanation, please watch the above video and do like, share and subscribe the channel. \u2764\uFE0F Also, please do upvote the solution if you liked it.\n\n# Subscribe:- [ReelCoding](https://www.youtube.com/@reelcoding?sub_confirmation=1)\n\nSubscribe Goal:- 500\nCurrent Subscriber:- 473\n# Complexity\n- Time complexity: O(nlogn)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    private int minDiff(List<Integer> nums) {\n        int n = nums.size();\n        return Math.min(\n                Math.min(nums.get(n - 1) - nums.get(3), nums.get(n - 2) - nums.get(2)),\n                Math.min(nums.get(n - 3) - nums.get(1), nums.get(n - 4) - nums.get(0))\n        );\n    }\n\n    public int minDifference(int[] nums) {\n        if (nums.length <= 4) return 0;\n        \n        Arrays.sort(nums);\n        \n        List<Integer> numsList = new ArrayList<>();\n        for (int num : nums) {\n            numsList.add(num);\n        }\n\n        return minDiff(numsList);\n    }\n}\n```\n\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    private int minDiff(List<Integer> nums) {\n        int n = nums.size();\n        return Math.min(\n                Math.min(nums.get(n - 1) - nums.get(3), nums.get(n - 2) - nums.get(2)),\n                Math.min(nums.get(n - 3) - nums.get(1), nums.get(n - 4) - nums.get(0))\n        );\n    }\n\n    private int minDiffViaPq(List<Integer> nums) {\n        PriorityQueue<Integer> maxHeap = new PriorityQueue<>(Collections.reverseOrder());\n        PriorityQueue<Integer> minHeap = new PriorityQueue<>();\n\n        for (int el : nums) {\n            maxHeap.add(el);\n            minHeap.add(el);\n\n            if (maxHeap.size() > 4) maxHeap.poll();\n            if (minHeap.size() > 4) minHeap.poll();\n        }\n\n        int l = 3;\n        int r = nums.size() - 4;\n        while (!maxHeap.isEmpty()) {\n            nums.set(l--, maxHeap.poll());\n            nums.set(r++, minHeap.poll());\n        }\n        return minDiff(nums);\n    }\n\n    public int minDifference(int[] nums) {\n        if (nums.length <= 4) return 0;\n        \n        List<Integer> ans = new ArrayList<>();\n        for (int num : nums) {\n            ans.add(num);\n        }\n\n        return minDiffViaPq(ans);\n    }\n}\n```
['Java']