C++ || PRIORITY QUEUE || EASY TO IMPLEMENT || BEGINNER FRIENDLY
Make a min-heap of pair of absolute difference and value corresponding to each element in the array arr.\n insert the elements one by one \n pop k elements and 
* Make a min-heap of pair of absolute difference and value corresponding to each element in the array arr.\n* insert the elements one by one \n* pop k elements and store them in array and return.\n\n```\n\nvector<int> findClosestElements(vector<int>& arr, int k, int x) {\n\n    // making a min-heap of absolute difference and corresponding array value\n\tpriority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;\n\n    // store the difference one by one with the array value\n\tfor (int i = 0; i < arr.size(); i++)\n\t\tpq.push({abs(arr[i] - x), arr[i]});\n\n\tvector<int> ans;\n\n    // get the top of the heap i.e. the element with minimum absolute difference\n\tfor (int i = 0; i < k; i++)\n\t{\n\t\tans.push_back(pq.top().second);\n\t\tpq.pop(); // pop it k times\n\t}\n\n\tsort(ans.begin(), ans.end());\n\treturn ans;\n}\n```\n\n\nalso ,\ncan be implemented using max-heap \n* make a max-heap and keep storing the pair of (absolute difference with x, corresponding key)\n* if the size of heap becomes more than k, just pop it (this will remove the element with largest absolute difference).\n* like this iterate over the array.\n* return the elements of the heap.\n\n```\n  vector<int> findClosestElements(vector<int>& arr, int k, int x) {\n        \n        priority_queue<pair<int,int>> pq;\n        \n        for(int i=0;i<arr.size();i++)\n            {pq.push({abs(arr[i]-x),arr[i]});\n              if(pq.size()>k)\n                  pq.pop();\n            }\n        vector<int> ans;\n        while(pq.size()>0)\n        {\n            ans.push_back(pq.top().second);\n            pq.pop();\n        }\n        sort(ans.begin(),ans.end());\n        return ans;\n    }\n```
['Heap (Priority Queue)', 'C++']