This is Amazon's most common warm-up problem. You track the minimum price seen so far and compute the maximum profit at each step. It tests whether you can think in terms of running state rather than comparing all pairs.
Solve it on LeetCode, then check your approach in the full walkthrough. One pass gives you time and space. You're expected you to finish this in under minutes.