Runtime: 0 ms, Beats 100.00%, Memory: 9.49 MB, Beats 92.46%
ApproachSingle loop fetch min and max logic, and then calculate max profitComplexity

Time complexity:
0 ms, Beats 100.00%


Space complexity:
9.49 MB, Beats 92
# Approach
Single loop fetch min and max logic, and then calculate max profit

# Complexity
- Time complexity:
0 ms, Beats 100.00%

- Space complexity:
9.49 MB, Beats 92.46%

# Code
```golang []
func maxProfit(prices []int) int {
    profit, min, max := 0, prices[0], prices[0]

    for _, v := range prices {
        if v < min {
            min  = v
            max = v
        } else if v > max {
            max = v
        }
        if (max-min) > profit {
            profit = max-min
        }
    }
    return profit
}
```
['Go']