Two pointer implementation question(It took couple of minutes to figure out the logic 🤨)
\nclass Solution\n{\n    public:\n        vector<int> getStrongest(vector<int> &arr, int k)\n        {\n            vector<int> vec;\n            sort(arr.begin
```\nclass Solution\n{\n    public:\n        vector<int> getStrongest(vector<int> &arr, int k)\n        {\n            vector<int> vec;\n            sort(arr.begin(), arr.end());\n            int med = arr[(arr.size() - 1) / 2];\n            int i = 0;//Take one pointer at starting\n            int j = arr.size() - 1;//Take one pointer from end\n\t\t\t//Simple Logic - in a sorted array the median is the middle most value and the distance of points from the extremes of the array is maximum  from the median(Try to think it as a number line ).\n\t\t\t//As we move toward the median from end points its distance starts decreasing(That\'s the meaning of median)\n            while (vec.size() != k)\n            {\n                int di = abs(med - arr[i]);\n                int dj = abs(med - arr[j]);\n                if (di > dj)\n                    vec.push_back(arr[i++]);\n                else if (dj > di)\n                    vec.push_back(arr[j--]);\n                else\n                {\n                    if (arr[i] > arr[j])\n                        vec.push_back(arr[i++]);\n                    else\n                        vec.push_back(arr[j--]);\n                }\n            }\n            return vec;\n        }\n};\n```
['Two Pointers']