← Back to companies
[ OK ] Loaded —
[ INFO ]
$ cd
$ ls -lt
01
02
03
04
05
$ ls -lt
01
02
03
04
05
user@intervues:~/$
Given an array prices where prices[i] is the stock price on day i, find the maximum profit from one transaction (buy one, sell one share).
If no profit is possible, return 0.
Constraints:
Example 1:
Input: prices = [7, 1, 5, 3, 6, 4] Output: 5 Explanation: Buy at 1, sell at 6 for profit 5
Example 2:
Input: prices = [7, 6, 4, 3, 1] Output: 0 Explanation: Prices only decrease, no profit possible
Related: Best Time to Buy and Sell Stock II - Multiple Transactions - allows multiple transactions
Source: Apple Phone Screen