C++✅✅ | Beginner Friendly Approach | Sorting + Vector of Pairs |
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    vector<int> getStrongest(vector<int>& arr, int k) {\n\n        sort(arr.begin(),arr.end());\n        int mid = arr[(arr.size()-1)/2];\n\n        vector<pair<int,int>>vp;\n\n        for(auto it : arr)\n        {   int temp = abs(it-mid);\n            vp.push_back(make_pair(temp,it));\n        }\n        \n        sort(vp.begin(),vp.end(),greater<pair<int,int>>());\n        \n        vector<int>ans;\n\n        for(int i=0;i<k;++i)\n        {\n            ans.push_back(vp[i].second);\n        }\n        return ans;\n    }\n};\n```
['C++']