C++ | beats 100% in memory and time | O(n Log n) | sorting
No mater which algo we perform on this question, we need to sort (in O(n Log n)) our array first.\nThe basic idea is after we sort our array, then we will check
**No mater which algo we perform on this question, we need to sort (in O(n Log n)) our array first.**\nThe basic idea is after we sort our array, then we will check values from beginning and last for the condition mentioned in question (abs(arr[j] - median) > abs(arr[i] - median)) to find strong elements.\nWe will increment or decrement the index according to requirement from the side where we find last strong component.\n```\nvector<int> getStrongest(vector<int>& arr, int k) {\n\tsort(arr.begin(), arr.end());\n\tint m = arr.size() - 1 >> 1;\n\tvector<int> ans;\n\tint i = 0, j = arr.size() - 1;\n\twhile(k > 0) {\n\t\tint val1 = abs(arr[j] - arr[m]), val2 = abs(arr[i] - arr[m]);\n\t\tif(val2 > val1) {\n\t\t\tans.push_back(arr[i]);\n\t\t\ti++;\n\t\t}\n\t\telse {\n\t\t\tans.push_back(arr[j]);\n\t\t\tj--;\n\t\t}\n\t\tk--;\n\t}\n\treturn ans;\n}\n```
['C', 'Sorting', 'C++']