Input: x = 7, arr[] = [10, 5, 3, 9, 2]
Output: arr[] = [5, 9, 10, 3, 2]
Explanation: abs(7 - 10) = 3, 7 - 5 = 2, 7 - 3 = 4 , abs(7 - 9) = 2 and 7 - 2 = 5,So according to the difference with X, elements are arranged as 5, 9, 10, 3, 2.
Input: x = 6, arr[] = [1, 2, 3, 4, 5]
Output: arr[] = [5, 4, 3, 2, 1]
Explanation: When sorted on the basis of absolute difference with x the elements will be sorted in the given order.
Note: In C++, self-balancing-binary-search-tree is implemented by set, map, and multimap. We can't use set here as we have key-value pairs (not only keys). We also can't directly use map also as a single key can belong to multiple values and map allows a single value for a key. So we use multimap which stores key-value pairs and can have multiple values for a key.