C++(Kadens algo)
TIme complexity:O(n)\nspace complexity:(1)\n\nclass Solution {\npublic:\n    int maxProfit(vector<int>& prices) {\n        int profit=0;\n        int minelem=pr
**TIme complexity:O(n)\nspace complexity:(1)**\n```\nclass Solution {\npublic:\n    int maxProfit(vector<int>& prices) {\n        int profit=0;\n        int minelem=prices[0];\n        for(int i=1;i<prices.size();i++){\n           minelem=min(prices[i],minelem);\n            profit=max(profit,(prices[i]-minelem));\n        }\n        return profit;\n    }\n};\n```\nif you like the solution ,upvote it.
['C', 'C++']