🚩Easy C++ O(N) Soln. [ FAANG😱 Interview Optimized code ]
\n# Complexity\n- Time complexity: O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(1)\n Add your space complexity here, e.g. O(n) \n\n
\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code \uD83D\uDCA1\n```\nclass Solution {\npublic:\n    int maxProfit(vector<int>& prices) {\n        int low = prices[0], curr_profit = 0, ovr_profit = 0;\n        for(int  i = 1; i < prices.size(); i++){\n            if(prices[i]<low){\n                low = prices[i];\n            }\n            curr_profit = prices[i]-low;\n            if(curr_profit > ovr_profit)\n                ovr_profit = curr_profit;\n        }\n        return ovr_profit;\n    }\n};\n```\n\n# **Please Upvote if it helps \uD83D\uDE4F**
['Array', 'Dynamic Programming', 'C++', 'Java', 'Python3']