✅✅Faster || Easy To Understand || C++ Code
Approach 1 :- Using Sorting\n\n Time Complexity :- O(NlogN)\n\n Space Complexity :- O(1)\n\n\nclass Solution {\npublic:\n    \n    int minimumDifference(vector<
* ***Approach 1 :- Using Sorting***\n\n* ***Time Complexity :- O(NlogN)***\n\n* ***Space Complexity :- O(1)***\n\n```\nclass Solution {\npublic:\n    \n    int minimumDifference(vector<int>& nums, int k) {\n        \n        // sort the array\n        \n        sort(nums.begin(), nums.end());\n        \n        int mini = INT_MAX;\n        \n        // take the k elements in a group\n        \n        for(int i = 0; i < nums.size(); i++)\n        {\n            if(i + k - 1 < nums.size())\n            {\n                int diff = nums[i + k - 1] - nums[i];\n                \n                mini = min(mini, diff);\n            }\n            else\n            {\n                break;\n            }\n        }\n        \n        return mini;\n    }\n};\n```
['C', 'Sorting', 'C++']