To solve this problem, you can keep track of the minimum price seen so far and the maximum profit that can be made by selling at the current price. You iterate through the array and update the minimum price and maximum profit as you go along. Finally, return the maximum profit.

Here's the code:

```
def maxProfit(prices):
    if not prices:
        return 0
    
    min_price = prices[0]
    max_profit = 0
    
    for price in prices:
        if price < min_price:
            min_price = price
        else:
            profit = price - min_price
            if profit > max_profit:
                max_profit = profit
                
    return max_profit
```

Example usage:
```
print(maxProfit([7,1,5,3,6,4])) # Expected output: 5 (buy on day 2 at price 1 and sell on day 5 at price 6)
print(maxProfit([7,6,4,3,1])) # Expected output: 0 (cannot make a profit)
```
You are given an array prices where prices[i] is the price of a given stock on the `i_th` day. You want to maximize your profit by choosing a single day to buy one stock and choosing a different day in the future to sell that stock. Return the maximum profit you can achieve from this transaction. If you cannot achieve any profit, return 0.