Easy || 100% || Kadane's Algorithm (Java, C++, Python, JS, Python3) || Min so far
Given an array prices where prices[i] is the price of a given stock on the ith day.\nmaximize our profit by choosing a single day to buy one stock and choosing 
Given an array prices where prices[i] is the price of a given stock on the ith day.\nmaximize our profit by choosing a single day to buy one stock and choosing a different day in the future to sell that stock.\nReturn the maximum profit achieve from this transaction. If you cannot achieve any profit, return 0\n\n**Example:**\nInput: prices = [7,1,5,3,6,4]\nOutput: 5\n**Explanation:** Buy on day 2 (price = 1) and sell on day 5 (price = 6), profit = 6-1 = 5.\n**Note that, buying on day 2 and selling on day 1 is not allowed because we must buy before sell.**\n# **Java Solution:**\nRuntime: 1 ms, faster than 98.59% of Java online submissions for Best Time to Buy and Sell Stock.\n```\nclass Solution {\n    public int maxProfit(int[] prices) {\n        // Base case...\n        // If the array is empty or its length <= 1, return 0...\n        if(prices == null || prices.length <= 1) return 0;\n        // Initialize the minimum price to buy...\n        int minBuy = prices[0];\n        // Initialize the maximum profit...\n        int profit = 0;\n        // Traverse all elements through a for loop...\n        for(int i = 1; i < prices.length; i++) {\n            // Get the minimum price to buy...\n            minBuy = Math.min(minBuy, prices[i]);\n            // Get maximum profit...\n            profit = Math.max(profit, prices[i] - minBuy);\n        }\n        return profit;      //return the maximum profit...\n    }\n}\n```\n\n# **C++ Solution:**\n```\nclass Solution {\npublic:\n    int maxProfit(vector<int>& prices) {\n        if(prices.size() == 0) return 0;\n        int profit = 0;\n        int low = prices[0], high = prices[0];\n        for(int i = 0; i < prices.size(); i++){\n            if(prices[i] < low){\n                profit = max(profit, high - low);\n                low = prices[i];\n                high = prices[i];\n            }else{\n                high = max(high, prices[i]);\n            }\n        }\n        profit = max(profit, high - low);\n        return profit;\n    }\n};\n```\n\n# **Python Solution:**\n```\nclass Solution(object):\n    def maxProfit(self, prices):\n        if len(prices) == 0: return 0\n        else:\n            profit = 0\n            minBuy = prices[0]\n            for i in range(len(prices)):\n                profit = max(prices[i] - minBuy, profit)\n                minBuy = min(minBuy, prices[i])\n            return profit\n```\n            \n# **JavaScript Solution:**\n```\nvar maxProfit = function(prices) {\n    if(prices == null || prices.length <= 1) return 0;\n    let minBuy = prices[0];\n    let profit = 0;\n    for(let i = 1; i < prices.length; i++) {\n        minBuy = Math.min(minBuy, prices[i]);\n        profit = Math.max(profit, prices[i] - minBuy);\n    }\n    return profit;\n};\n```\n\n# **Python3 Solution:**\n```\nclass Solution:\n    def maxProfit(self, prices: List[int]) -> int:\n        if len(prices) == 0: return 0\n        else:\n            profit = 0\n            minBuy = prices[0]\n            for i in range(len(prices)):\n                profit = max(prices[i] - minBuy, profit)\n                minBuy = min(minBuy, prices[i])\n            return profit\n```\n**I am working hard for you guys...\nPlease upvote if you found any help with this code...**
['C', 'Python', 'Java', 'Python3', 'JavaScript']