🚀✅ || Image Representation || Well Explained || JAVA || Sorting
Intuition\n Describe your first thoughts on how to solve this problem. \nGiven in the question, we need to partition the array into 2 sub arrays such that the a
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nGiven in the question, we need to partition the array into 2 sub arrays such that the absolute difference between the max element of first array and min element of second array.\n\nLet\'s think can we solve this by using Brute force approach as per given constraints?\nThe answer is no, absolutely it will be a TLE.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nHow about using the sorting property as when the elements are in a particular order then their adjacent difference will be less right.\nIf we choose any inbetween index, the max element will be at leftmost of first array and min element will be at rightmost of second array.\nSo, by finding the adjacency difference between the elements, we can partition the array into two subarrays.\nSteps : \n1. Sort the array.\n2. Find the min adjacency difference between the elements.\n\nBelow example picture will give you the clear understanding.\n\n\n![leetcode_june_18.jpg](https://assets.leetcode.com/users/images/48b495ca-8f09-4198-ba04-09a88104ab5e_1687059909.3547559.jpeg)\n\n\n\n# Complexity\n- Time complexity: $$O(N*logN)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: Amortized $$O(1)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n![upvote cat.jpeg](https://assets.leetcode.com/users/images/cdfc2b6b-cf9a-4eac-a7f0-e055f86d1237_1687060624.0958745.jpeg)\n\n\n\n# Code\n```java []\nclass Solution {\n    public int findValueOfPartition(int[] nums) {\n        int min=Integer.MAX_VALUE;\n        Arrays.sort(nums); //step-1\n        \n        for(int i=1;i<nums.length;i++)\n        {\n            if( (nums[i]-nums[i-1])<min ) //step-2\n            {\n                min=(nums[i]-nums[i-1]);\n            }\n            \n        }\n        \n        return min;\n        \n    }\n}\n```\n\n
['Array', 'Sorting', 'Merge Sort', 'Java']