[C++] Using pairs and custom comparator
Pls upvote if you find this helpful  :)\nThe basic idea is to first get the array sorted and find the median .After getting median we store the absolute differe
***Pls upvote if you find this helpful  :)***\nThe basic idea is to first get the array sorted and find the median .After getting median we store the absolute difference of the array values and median and the value itself in an array of pairs.And then we define our custom comparator for the purpose.\nAt last we find the first k values from the sorted array of pairs .Remember we have stored pairs in the second array(**answer**).So while returning the desired array(**answer1**)store the second value of pair from answer.\n```\nclass Solution {\npublic:\n    vector<int> getStrongest(vector<int>& arr, int k) {\n        sort(arr.begin(),arr.end());\n        vector<int>answer1;\n        int m=arr.size();\n        int median=arr[(m-1)/2];\n        vector<pair<int,int>> answer;\n        for(auto i:arr){\n            answer.push_back(make_pair(abs(i-median),i));\n        }\n        sort(answer.begin(),answer.end(),[]( pair<int,int>a,pair<int,int> b){\n           return (a.first>b.first)||(a.first==b.first&&a.second>b.second);\n        });\n        for(int i=0;i<k;i++) answer1.push_back(answer[i].second);\n        return answer1;\n    }\n};\n```
['C', 'C++']