FastPrepMaximum Stock Profit with One Transaction
Problems/Maximum Stock Profit with One Transaction

Maximum Stock Profit with One Transaction

Expedia logoExpedia● EasyNEW GRADINTERNOAONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The source omits numeric bounds. The one-transaction objective and first example match the source at about 98%.

You are given an array prices, where prices[i] is the price of a stock on day i.

You may buy one share on one day and sell it on a later day. Return the maximum profit from at most one such transaction. You may choose no transaction, which gives a profit of zero.

Function

maxProfit(prices: int[]) → int

Examples

Example 1

prices = [2,100,150,120]return = 148

Buy at price 2 on day 0 and sell at price 150 on day 2. The profit is 150 - 2 = 148.

Example 2

prices = [7,6,4,3,1]return = 0

Every later price is lower than every earlier price. Choosing no transaction gives the best profit, 0.

Constraints

  • 1 <= prices.length <= 100000.
  • 0 <= prices[i] <= 1000000000.

More Expedia Online Assessment questions

  • Balanced NumbersOA · Seen Aug 2026
  • REST API: Discounted PriceOA · Seen Aug 2026
  • Maximum Team SizeOA · Seen Mar 2026
  • Per-Domain Request LimiterOA · Seen Oct 2025
  • Count Equal-Frequency SubsequencesOA · Seen Mar 2025
  • Count Increasing Stock PeriodsOA · Seen Mar 2025
  • Get Minimum StepsOA · Seen Oct 2024
  • Rank Songs by PopularityOA · Seen Oct 2024
  • Calculate the SumOA · Seen Oct 2024
  • Get Maximum EfficiencyOA · Seen Oct 2024

Similar questions at other companies

  • Catch Fish with Reusable BaitsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
  • Server InvestmentRippling · OARippling interview questions
  • Book Reading EveningsGoogle · OAGoogle interview questions
  • Maximum Apples That Fit in a BoxVirtu Financial · OAVirtu Financial interview questions
  • Minimum Project Bid CostNVIDIA · OANVIDIA interview questions
  • Maximum Profit with Exactly One Stock TransactionRetool · PHONE SCREEN · ONSITE INTERVIEWRetool interview questions
  • Minimum AmountBelvedere Trading · OA
  • Maximum Income from Asset TradingJefferies · OA
  • Best Time to Buy and Sell Stock IIGroww · ONSITE INTERVIEW
  • Maximum Three-Server Difficulty ScoreVisa · OAVisa interview questions

Interview reports that mention this question

  • Expedia Intern Finals Before 2020: 14 Experiences (Part 6 of 6)
  • Expedia Intern Final Round in 2020: 24 Experiences (Part 5 of 6)
  • Expedia New Grad SDE Earlier Loops: 5 Experiences (Part 2 of 3)

Expedia interview experiences

  • Expedia Intern Final Round in 2021: 28 Experiences (Part 4 of 6)
  • Expedia Intern Final Round in 2022: 15 Experiences (Part 3 of 6)
  • Expedia Intern Final Round in 2023: 17 Experiences (Part 2 of 6)
All Expedia interview questionsSee Expedia hiring insights
Saved
class Solution {
    public int maxProfit(int[] prices) {
        // Write your code here.
    }

}
Checking account…