Problem Statement

Pattern: Pattern Sliding Window


Solution

public long findMinDiff (ArrayList<Integer> nums, int n, int m)
{
	Collections.sort(nums);
	int start = 0, end = start + m - 1;
	long minDiff = Long.MAX_VALUE;
	
	while(end < n) {
		minDiff = Math.min(minDiff, (long) (nums.get(end) - nums.get(start)));
		end++; start++;
	}
	
	return minDiff;
}

Notes

  • sort, sliding window.