Easy Solution || Using Heap || C++;
\n# Code\n\nclass Solution {\npublic:\n    vector<int> findClosestElements(vector<int>& arr, int k, int x) {\n        // priority_queue<pair<int,int>,vector<pai
\n# Code\n```\nclass Solution {\npublic:\n    vector<int> findClosestElements(vector<int>& arr, int k, int x) {\n        // priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>p;\n        priority_queue<pair<int,int>> p;\n          vector<int>v;\n        for(auto i:arr){\n            int n=abs(x-i);\n         p.push({n,i});\n\n            if(p.size()>k){\n                 p.pop();\n            }\n        }\n        while(p.size()>0){\n            v.push_back(p.top().second);\n            p.pop();\n        }\n        sort(v.begin(),v.end());\n        return v;\n\n    }\n};\n```
['C++']