I have removed the Math.max calculation and directly added profit only on days when the stock price increased simplifying the logic and improving readability.
This greedy approach accumulates profit efficiently by capturing only the upward price trends.
I have removed the Math.max calculation and directly added profit only on days when the stock price increased simplifying the logic and improving readability. This greedy approach accumulates profit efficiently by capturing only the upward price trends.