Easiest Solution | [C++] | Basic Approach
Approach\n Describe your approach to solving the problem. \nIf we have to take difference of MAX and MIN Element in a pack of K elements, then why not sort it a
# Approach\n<!-- Describe your approach to solving the problem. -->\nIf we have to take difference of MAX and MIN Element in a pack of K elements, then why not sort it and take 2 Pointers placed at 0th Position and (0+k-1)th Position respectively and take the difference of both and continue the same process until array is finished.\n \n\n# Code\n```\nclass Solution {\npublic:\n    int minimumDifference(vector<int>& nums, int k) {\n        int i = 0;\n        int j = k-1;\n        sort(nums.begin(), nums.end());\n        int n = nums.size();\n        int ans =INT_MAX;\n        while(j<n){\n           ans = min(ans,nums[j++]-nums[i++]);\n        }\n        return ans;\n    }\n};\n```
['C++']