Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Maximize Profit from Stock Prices
00:00
5 left

Maximize Profit from Stock Prices

EasyPython

Problem

Given an array of integers 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. You may complete at most one transaction (i.e., buy one and sell one share of the stock). If you cannot achieve any profit, return 0.

Constraints

  • 1 <= prices.length <= 10^5
  • 0 <= prices[i] <= 10^4

Function Signature

def max_profit(prices: list[int]) -> int:
Interviewer

Your question is Maximize Profit from Stock Prices. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.