Shortest, Easiest & Well Explained || To the Point & Beginners Friendly Approach (❤️ ω ❤️)
Welcome to My Coding Family\u30FE(\u2267 \u25BD \u2266)\u309D\nThis is my shortest, easiest & to the point approach. This solution mainly aims for purely beginn
# Welcome to My Coding Family\u30FE(\u2267 \u25BD \u2266)\u309D\n*This is my shortest, easiest & to the point approach. This solution mainly aims for purely beginners so if you\'re new here then too you\'ll be very easily be able to understand my this code. If you like my code then make sure to UpVOTE me. Let\'s start^_~*\n\n# Approach:-\n\n1. First create a pair of vector of data type integer to store the numbers pairwise so that we can sort it later.\n2. Now, sort the given vector \'v\' in ascending/increasing order to get the median from vector \'v\'.\n3. Use v[(v.size()-1)/2] formula for getting the median & store it inside an integer \'m\'.\n4. Now iterate from the 0th till the end index of vector \'v\' & insert the pair of absolute value of ith element minus \'m\' of vector \'v\' & ith element of \'v\' i.e. {abs(v[i]-m),v[i]} inside our vector pair \'p\'.\n5. Now as we\'re done with vector \'v\' then clear vector \'v\' & sort the vector pair \'p\' in decending/decreasing order.\n6. Now at the end, just iterate from the 0th till \'k\' inside vector pair \'p\' and insert all the second element of p[i] inside vector \'v\'. Then return \'v\' as answer.\n\n**The code is given below for further understanding(p\u2267w\u2266q)**\n\n# Code\n```\nclass Solution {\npublic:\n    vector<int> getStrongest(vector<int>& v, int k) {\n        vector<pair<int,int>>p;\n        sort(v.begin(),v.end());\n        int m=v[(v.size()-1)/2];\n        for(auto i:v)p.push_back({abs(i-m),i});\n        v.clear();\n        sort(p.rbegin(),p.rend());\n        for(int i=0;i<k;i++)v.push_back(p[i].second);\n        return v;\n\n// if my code helped you then please UpVOTE me, an UpVOTE encourages me to bring some more exciting codes for my coding family. Thank You o((>\u03C9< ))o\n    }\n};\n```\n\n![f5f.gif](https://assets.leetcode.com/users/images/0baec9b8-8c77-4920-96c5-aa051ddea6e4_1702180058.2605765.gif)\n![IUeYEqv.gif](https://assets.leetcode.com/users/images/9ce0a777-25fd-4677-8ccc-a885eb2b08f0_1702180061.2367256.gif)
['C++']