PracHub
QuestionsCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates algorithmic problem-solving skills with emphasis on array processing, numeric optimization, and time/space complexity analysis in the coding & algorithms domain. It is commonly asked to assess practical implementation ability and efficiency trade-offs under input-size constraints, and the level of abstraction is practical application rather than purely conceptual reasoning.

  • nan
  • Two Sigma
  • Coding & Algorithms
  • Data Scientist

Maximize profit from one stock trade

Company: Two Sigma

Role: Data Scientist

Category: Coding & Algorithms

Difficulty: nan

Interview Round: Technical Screen

## Problem You are given an integer array `prices` where `prices[i]` is the price of a stock on day `i`. You may complete **at most one transaction**: choose a day to buy one share and a later day to sell that share. Return the **maximum profit** you can achieve. If no profit is possible, return `0`. ### Input - `prices`: array of integers, length `n` ### Output - An integer: maximum achievable profit ### Constraints - `1 <= n <= 2 * 10^5` - `0 <= prices[i] <= 10^9` ### Example - Input: `prices = [7,1,5,3,6,4]` - Output: `5` (buy at `1`, sell at `6`)

Quick Answer: This question evaluates algorithmic problem-solving skills with emphasis on array processing, numeric optimization, and time/space complexity analysis in the coding & algorithms domain. It is commonly asked to assess practical implementation ability and efficiency trade-offs under input-size constraints, and the level of abstraction is practical application rather than purely conceptual reasoning.

Return the maximum profit from one buy before one sell, or 0 if no profit is possible.

Constraints

  • Inputs are Python literals matching the function signature.
  • Return a deterministic exact-match value.

Examples

Input: ([7,1,5,3,6,4],)

Expected Output: 5

Explanation: Prompt example.

Input: ([7,6,4,3,1],)

Expected Output: 0

Explanation: No profit.

Input: ([1],)

Expected Output: 0

Explanation: Single day.

Hints

  1. Use deterministic tie-breaking for prompts with multiple valid outputs.
  2. For design-style APIs, simulate operations with explicit inputs.
Last updated: Jun 27, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ 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
  • AI Coding 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.

Related Coding Questions

  • Implement Price-Time Order Matching - Two Sigma (medium)
  • Compute Piecewise Linear Interpolation - Two Sigma (medium)
  • Implement an In-Memory Database - Two Sigma (hard)
  • Merge two sorted linked lists - Two Sigma (hard)
  • Merge Two Sorted Lists - Two Sigma (hard)