PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/Meta

Maximize one stock trade profit

Last updated: Mar 29, 2026

Quick Overview

This question evaluates algorithm design skills for single-pass array processing, streaming data handling, and time/space complexity analysis within the Coding & Algorithms domain.

  • Medium
  • Meta
  • Coding & Algorithms
  • Machine Learning Engineer

Maximize one stock trade profit

Company: Meta

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Onsite

You're given an array prices of length n where prices[i] is the stock price on day i. You may complete at most one transaction (buy once, then sell later). Return the maximum possible profit; if no profit is possible, return 0. Constraints: 1 <= n <= 100000, 0 <= prices[i] <= 1e9. Requirements: O(n) time and O( 1) extra space. Provide the algorithm, prove correctness, and analyze complexity. Follow-up: adapt your solution to a streaming setting where prices arrive one by one and you must output the current best profit after each new price.

Quick Answer: This question evaluates algorithm design skills for single-pass array processing, streaming data handling, and time/space complexity analysis within the Coding & Algorithms domain.

Related Interview Questions

  • Solve Two Backtracking Array Problems - Meta (hard)
  • Solve Array, Matrix, and Recommendation Problems - Meta (medium)
  • Find a String Containing Another - Meta (medium)
  • Solve Subarray Sum and Local Minimum - Meta (hard)
  • Validate abbreviations and brackets - Meta (medium)
Meta logo
Meta
Sep 6, 2025, 12:00 AM
Machine Learning Engineer
Onsite
Coding & Algorithms
1
0

You're given an array prices of length n where prices[i] is the stock price on day i. You may complete at most one transaction (buy once, then sell later). Return the maximum possible profit; if no profit is possible, return 0. Constraints: 1 <= n <= 100000, 0 <= prices[i] <= 1e9. Requirements: O(n) time and O(

  1. extra space. Provide the algorithm, prove correctness, and analyze complexity. Follow-up: adapt your solution to a streaming setting where prices arrive one by one and you must output the current best profit after each new price.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Meta•More Machine Learning Engineer•Meta Machine Learning Engineer•Meta Coding & Algorithms•Machine Learning Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.