Sliding Window • Easy
Best Time to Buy Stock
You are given an array `prices` where `prices[i]` is the price of a given stock on the `i`-th day. Return the maximum profit you can achieve from this transaction.
The Challenge
You are given an array `prices` where `prices[i]` is the price of a given stock on the `i`-th day. Return the maximum profit you can achieve from this transaction.
Pro-tip: Keep track of the minimum price seen so far and calculate the profit for each day.
Solution.swift Tests.swift
Output
Ready to run.