Algorithm · Apple · Medium
Part 1: Maximum Single-Transaction Stock Profit Algorithm Scan the array once from left to right. While scanning: Keep the minimum stock price seen so far. For the current price, compute the profit if selling today after buying at that minimum. Update the maximum profit if this profit is larger. If all prices decrease or the array is empty, no positive profit is possible, so return 0. Python implementation Complexity Time complexity: $$O(n)$$, where n is the length of…
Checking your access…