Input: arr[] = {12, 10, 102, 31, 15}, K = 102
Output: 102 10 31 12 15
Explanation:
Elements at their respective distance from K are,
At distance 0: 102
At distance 1: 10, 31 in sorted form.
At distance 2: 12, 15 in sorted form.
Hence, our resultant array is [ 102, 10, 31, 12, 15 ]
Input: arr[] = {14, 1101, 10, 35, 0}, K = 35
Output: 35 0 10 1101 14
Explanation:
Elements at their respective distance from K are,
At distance 0: 35
At distance 1: 10, 0 and in sorted form we have 0, 10.
At distance 2: 1101
At distance 3: 14
Hence, our resultant array is [ 35, 0, 10, 1101, 14 ]