5 lines sol || C++ || Easy to undersatand
\n\nclass Solution {\npublic:\n    int maxProfit(vector& prices) {\n        int maxpro = 0;\n        int minprice = INT_MAX;\n        for(int i=0;i<prices.size(
```\n\n```class Solution {\npublic:\n    int maxProfit(vector<int>& prices) {\n        int maxpro = 0;\n        int minprice = INT_MAX;\n        for(int i=0;i<prices.size();i++){\n            minprice=min(prices[i],minprice);\n            maxpro=max(maxpro,prices[i]-minprice);\n        }\n        return maxpro;\n    }\n};\n\nTC : O(n)\nSC : O(1)\n\nfeel free to ask your doubts :)\nand ps upvote if it was helpful :)
['Dynamic Programming', 'C']