🔥Minimize the Gap: Smallest Difference Between Scores🔥
IntuitionThe essence of the problem lies in minimizing the difference between the highest and lowest scores in a subset of size ( k ). To achieve this, we need
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
The essence of the problem lies in minimizing the difference between the highest and lowest scores in a subset of size \( k \). To achieve this, we need to evaluate subsets where the scores are closely packed together, as such subsets are more likely to yield smaller differences. 

When the scores are sorted, subsets of consecutive elements inherently have the smallest range since the elements are arranged in increasing order. This allows us to efficiently find the subset with the minimum difference without the need to evaluate all possible combinations, making the solution both logical and computationally efficient.
# Approach
<!-- Describe your approach to solving the problem. -->
1. **Sort the Array**:  
   Begin by sorting the array. Sorting ensures that the scores are in ascending order, which allows us to consider subsets of \( k \) consecutive elements to minimize the difference.

2. **Initialize Pointers**:  
   Use two pointers, \( i \) (start of the subset) and \( j \) (end of the subset), to represent a window of size \( k \). Initially, set \( i = 0 \) and \( j = k - 1 \).

3. **Sliding Window to Evaluate Differences**:  
   Slide the window across the sorted array:
   - Calculate the difference between the element at \( j \) (maximum in the window) and \( i \) (minimum in the window).
   - Update the minimum difference if the current difference is smaller.

4. **Continue Sliding**:  
   Increment both \( i \) and \( j \) until \( j \) reaches the end of the array. This ensures all subsets of size \( k \) are considered.

5. **Return the Result**:  
   Once the loop is complete, the smallest difference calculated is the answer.
# Complexity
- Time complexity:**O(NLogN)**
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:**O(1).**
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class Solution {
public:
    int minimumDifference(vector<int>& nums, int k) {
        sort(nums.begin(),nums.end());
        int i=0 , j=k-1;
        int mini=INT_MAX;
        while(j<=nums.size()-1)
        {
            mini=min(mini,(nums[j]-nums[i]));
            i++,j++;
        }
        return mini;
    }
};
```
['C++']