🚀Simplest Solution🚀 Beginner Friendly||🔥DP||🔥C++|| Python || Java
Consider\uD83D\uDC4D\n\n                    Please Upvote If You Find It Helpful\n\n# Intuition\nIn this question we have to find the Maximum Profit.\nSo, we fi
# Consider\uD83D\uDC4D\n```\n                    Please Upvote If You Find It Helpful\n```\n# Intuition\nIn this question we have to find the **Maximum Profit**.\nSo, we find the **stock with Minimum value** and then **check for maximum profit**.\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n    Example : prices = [7,1,5,3,6,4]\n    Initially `minValue` = INT_MAX, `profit` = 0\n    At index `0` \n        `minValue` = min(minValue, 7)\n        profit = max(profit, 7 - minValue)\n        so, `profit` = 0\n    At index `1` \n        minValue = min(minValue, 1)\n        profit = max(profit, 1 - 1)\n        so, `profit` = 0\n    At index `2` \n        minValue = min(minValue, 5)\n        profit = max(profit, 5 - 1)\n        so, `profit` = 4\n    At index `3` \n        minValue = min(minValue, 3)\n        profit = max(profit, 3 - 1)\n        so, `profit` = 4\n    At index `4` \n        minValue = min(minValue, 6)\n        profit = max(profit, 6 - 1)\n        so, `profit` = 5\n    At index `5` \n        minValue = min(minValue, 4)\n        profit = max(profit, 4 - 1)\n        so, `profit` = 5\n    So answer is `5`\n<!-- Describe your approach to solving the problem. -->\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\n```C++ []\nclass Solution {\npublic:\n    int maxProfit(vector<int>& prices) {\n        int minValue = INT_MAX;\n        int profit = 0;\n        for(int i=0;i<prices.size();i++){\n            minValue = min(minValue, prices[i]);\n            profit = max(profit, prices[i]-minValue);\n        }\n        return profit;\n    }\n};\n```\n```python []\nclass Solution:\n    def maxProfit(self, prices: List[int]) -> int:\n        minValue = 1e9\n        profit = 0\n\n        for i in range(len(prices)):\n            minValue = min(minValue, prices[i])\n            profit = max(profit, prices[i]-minValue)\n        \n        return profit\n```\n```Java []\nclass Solution {\n    public int maxProfit(int[] prices) {\n        int minValue = Integer.MAX_VALUE;\n        int profit = 0;\n        for (int i = 0; i < prices.length; i++) {\n            minValue = Math.min(minValue, prices[i]);\n            profit = Math.max(profit, prices[i] - minValue);\n        }\n        return profit;\n    }\n}\n\n```\n\n```\n                            Give a \uD83D\uDC4D. It motivates me alot\n```\nLet\'s Connect On [Linkedin](https://www.linkedin.com/in/naman-agarwal-0551aa1aa/)
['Dynamic Programming', 'Python', 'C++', 'Java', 'Python3']