Skip to content
LakeBench
ProblemsCommunityPricing
Sign inStart practicing

Best Time Buy Sell

Python data engineering interview problem. Difficulty: beginner. Pattern: Arrays. About 10 minutes. Free to practice.

Max profit from one buy and one later sell. Treat this as a production helper: match the contracted return shape, including empty and duplicate inputs.

Implement max_profit(prices: list) -> int for one transaction. (buy 1, sell 6).

Constraints

  • If no profit is possible, return 0.
  • Sell must be after buy.

Examples

Input: max_profit([7, 1, 5, 3, 6, 4]) Output: 5 Buy at 1, sell at 6.

Topics: lakebench, python, profit, scan.

More Python interview questions · All interview problems · Learn data engineering

beginner

Best Time Buy Sell

Interview-style drill: Max profit from one buy and one later sell.

Implement `max_profit(prices: list) -> int` for one transaction. Example: `[7, 1, 5, 3, 6, 4]` → `5` (buy 1, sell 6). Keep the harness.