Input: arr= [6, 5, 3, 2, 8, 10, 9], k = 3
Output: [2, 3, 5, 6, 8, 9, 10]
Input: arr[]= [1, 4, 5, 2, 3, 6, 7, 8, 9, 10], k = 2
Output: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
The main idea is to sort the array efficiently from left to right by considering elements from the right side. For each position i, we find the minimum element in the range [i, i + k] with help of min-heap. we don't need to check numbers from left side as they are already at their correct positions.