Very Fast || Explained line by line || Easy to understand
Intuition\n Describe your first thoughts on how to solve this problem. \nOur intution is to calculate minimum possible differance between maxmimum and minimum o
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nOur intution is to calculate minimum possible differance between maxmimum and minimum of any K integer from given arry `nums`.\n\n---\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n- **Sorting:** If we sort the list than we can find min_difference by just find absulute difference between first and last element of subarray of k element.\n    - **Step 1.** sort the list `nums`\n    -  **Step 2.** initiate a variabel `min_diff` which will always get update with new mini_difference.\n    - **Step 3.** Initiate a for loop from `0` to size of `nums` - `k`.\n    -  **Step 4.** calulate absulute difference between current element and [current element position + k ]th element.\n    -  **Step 5.** keep update `min_diff` with new min(diff).\n    -  **Step 6.** come out of the loop and return the `min_diff` .\n- **Edge  case :** if only one element in list than return 0.\n---\n\n\n# Complexity\n- Time complexity: $$O(nlogn)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n![Screenshot 2024-07-23 094922.png](https://assets.leetcode.com/users/images/52a95bdf-81a0-4c26-b2b5-cb63fcc2d145_1724681230.6548967.png)\n\n- Space complexity: $$O(1)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n![Screenshot 2024-07-07 213721.png](https://assets.leetcode.com/users/images/56faba31-e2d2-41fe-8e06-bcf381eb3355_1724681260.6421852.png)\n\n---\n\n\n# Code\n```python3 []\nclass Solution:\n    def minimumDifference(self, nums: List[int], k: int) -> int:\n        if k == 1:\n            return 0\n        nums.sort()\n        min_diff = max(nums)\n        for i in range(len(nums)-k+1):\n            diff = abs(nums[i]- nums[i+k-1])\n            min_diff = min(min_diff, diff)\n        return min_diff\n\n            \n        \n```\n\n---\n\n![0cc080cf-616a-4180-b9e6-f46c49f183a8_1718170157.6093411.jpeg](https://assets.leetcode.com/users/images/ef015a64-a594-48f9-a106-a351758539a9_1724681196.9175792.jpeg)\n
['Sliding Window', 'Sorting', 'Iterator', 'Python3']