Best Stock Trade with Buy and Sell Days
Updated
Problem statement
You are given an array prices where prices[i] is the price of a stock on day i. You may buy the stock on one day and sell it on a later day, at most once.
The problem statement continues
ProExamples
Example 1
prices = [7,1,5,3,6,4]return = [1,4]- Buy on day 1 at price 1 and sell on day 4 at price 6 for a profit of 5, the largest possible.
FastPrep Pro
Reported in 1 Google interview this weekUnlock this recently reported problem
FastPrep Pro gives you full access to interview problems reported within the last week.
- Full problem statement and constraints
- 2 more worked examples, explained
- Guided hints and editorial
- Run your code on real test cases
$8.25/month
$99 billed yearly — or $19 month-to-month. Cancel anytime.
Free plan — 2 of 2 free unlocks used this week
More Google Phone Screen questions
- Word Chain Jumps in a GridPHONE SCREEN · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
- Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
- Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Logger Rate Limiter with Every-Arrival HistoryPHONE SCREEN · Seen Nov 2026
- Minimum Total Layover WaitPHONE SCREEN · Seen Nov 2026
- Reach a Destination Through Scheduled FlightsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Minimum Boards to Cover Roof HolesPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Can Place FlowersAgoda · PHONE SCREENAgoda interview questions
- Maximum Later Checkpoint Altitude GainYellow.ai · PHONE SCREEN
- Maximum Profit with Exactly One Stock TransactionRetool · PHONE SCREEN · ONSITE INTERVIEWRetool interview questions
- One Package for All ProductsAmazon · PHONE SCREEN
- Best Time to Buy and Sell StockOracle · PHONE SCREEN · ONSITE INTERVIEWOracle interview questions
- Best Time to Buy and Sell Stock IIPoint72 · PHONE SCREENPoint72 interview questions
- Best Time to Buy and Sell StockJP Morgan Chase · PHONE SCREENJP Morgan Chase interview questions
- Choose the Front Football TeamAnduril · PHONE SCREENAnduril interview questions
- Best Time to Buy and Sell StockBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Best Time to Buy and Sell StockHeadlands Technologies · PHONE SCREEN · ONSITE INTERVIEWHeadlands Technologies interview questions