O(n) Solution | Dynamic Programming | C++ | Optimal Solution | Detailed Explanation
\nYoutube link : https://youtu.be/0-6V7nDG8TY\nFollow for further updates.\n\nCODE :\n\nclass Solution {\npublic:\n    int maxProfit(vector<int>& prices) {\n   
\nYoutube link : https://youtu.be/0-6V7nDG8TY\nFollow for further updates.\n\n**CODE :**\n```\nclass Solution {\npublic:\n    int maxProfit(vector<int>& prices) {\n        \n        int profit=0;\n        int minvalue=INT_MAX;\n        \n        for(int i=0;i<prices.size();i++)\n        {\n            minvalue=min(minvalue,prices[i]);\n            profit=max(profit,prices[i]-minvalue);\n        }\n        \n        return profit;\n        \n    }\n};\n\n\n// FORMULA FOR CALCULATING PROFIT\n\n\n// profit=(price of stock on ith day)-(min value of stock till ith day)\n```
['Dynamic Programming', 'C', 'C++']