Simple C++ Solution [Runtime: 15 ms, faster than 61.54% . Memory Usage: 9.1 MB, less than 100.00%].
As in the Problem itself we are give an array and we have to return the sub-array of size k whose sum is maximum.\nWe can do this in a very simple way and witho
As in the Problem itself we are give an array and we have to return the sub-array of size k whose sum is maximum.\nWe can do this in a very simple way and without using any extra space or sorting it.\n* Step -1 -> Create an ans vector to return and store first k elements in that\n* Step -2 -> Loop through the remaining array\n* Step -3 -> At each step calculate the index of minimum element in the ans array and compare it with the current element.\n* Step -4 -> if element is greater then minimum element then remove minimum from ans and add the greater element.\n* Step -5 -> Repeat step 3 and 4 till last element.\n* Finally we have required sub sequence.\n\n### Below is the code Given [c++]\n```\nvector<int> maxSubsequence(vector<int>& nums, int k) {\n\t\t// Declare variables\n        int n = nums.size(), i = 0, t = k;\n\t\t// Answer Array\n        vector<int> ans;\n\t\t\n\t\t// Put first k elements\n        while(t>0){\n            ans.push_back(nums[i]);\n            i++;\n            t--;\n        }\n\t\t\n\t\t//Loop Through Remaining Array\n        for(int j=i;j<n;j++)\n        {\n\t\t\t// Calcualate minimum from ans array \n            int mini = min_element(ans.begin(), ans.end()) - ans.begin();\n\t\t\t// Comapre it with the current element\n            if(ans[mini] < nums[j]){\n                ans.erase(ans.begin()+mini);\n                ans.push_back(nums[j]);\n            }\n            \n        }\n        return ans;\n    }\n```\nTime Complexity - O(n*k)\nSpace Complexity - O(1)\n\n##### if You like my solution please Upvote it.[This is my first post \uD83D\uDE00]\n
['C', 'C++']