Java Simple Solution -Time O(n) Space O(1)
Kindly upvote if it helps you!\n```\npublic int maxProfit(int[] prices) {\n        int maxProfit = 0;\n\t\t//we buy the stock on the \'left\' day & plan on sell
Kindly upvote if it helps you!\n```\npublic int maxProfit(int[] prices) {\n        int maxProfit = 0;\n\t\t//we buy the stock on the \'left\' day & plan on selling on the \'right\' day\n        int left = 0, right = 1;\n        while(right < prices.length){\n\t\t\t//We want a profitable deal. Hence if the cost at day we buy the stock is less than the price on\n\t\t\t//the day we sell the stock, calculating currentProfit.\n\t\t\t//If currentProfit is greater that maxProfit, updating maxProfit\n            if(prices[left]<prices[right]){\n                int currentProfit = prices[right]-prices[left];\n                maxProfit = Math.max(maxProfit, currentProfit);\n            }else{\n\t\t\t\t//if we found a day having even less price , we will buy the stock at that day. \n                left = right;\n            }\n            right++;\n        }\n        return maxProfit;\n    }
['Two Pointers']