PracHub
QuestionsCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates algorithmic problem-solving skills, particularly efficient array processing and profit-optimization across single-transaction and multiple-transaction variants, along with time and space complexity analysis.

  • hard
  • Squarepoint
  • Coding & Algorithms
  • Data Scientist

Maximize profit from one or many stock trades

Company: Squarepoint

Role: Data Scientist

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Technical Screen

You are given an integer array `prices` where `prices[i]` is the price of a stock on day `i` (0-indexed). Answer the following two subproblems: 1. **Single transaction** - You may complete at most **one** transaction: choose one day to buy and a later day to sell (must buy before you sell). - You are not allowed to short-sell. - Return the **maximum profit** you can achieve. If you cannot make any profit, return `0`. 2. **Multiple transactions** - You may complete **as many transactions as you like** (i.e., buy and sell multiple times), but you **cannot hold more than one share at a time** (you must sell the stock before you buy again). - You are not allowed to short-sell. - Return the **maximum total profit** you can achieve. Assume: - `1 <= n <= 10^5`, where `n` is the length of `prices`. - `0 <= prices[i] <= 10^4`. Design efficient algorithms for both subproblems and analyze their time and space complexity.

Quick Answer: This question evaluates algorithmic problem-solving skills, particularly efficient array processing and profit-optimization across single-transaction and multiple-transaction variants, along with time and space complexity analysis.

Max Profit from One Stock Transaction

Return maximum profit from at most one buy before one sell.

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: Buy low sell high.

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

Expected Output: 0

Explanation: No profit.

Input: ([1],)

Expected Output: 0

Explanation: Single price.

Hints

  1. Choose a representation that makes the requested operation direct.
  2. Handle empty inputs and boundary cases first.

Max Profit from Many Stock Transactions

Return maximum total profit from any number of non-overlapping buy/sell transactions.

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: 7

Explanation: Take every positive rise.

Input: ([1,2,3,4,5],)

Expected Output: 4

Explanation: Monotone increasing.

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

Expected Output: 0

Explanation: No profit.

Hints

  1. Choose a representation that makes the requested operation direct.
  2. Handle empty inputs and boundary cases first.
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 EMA Crossovers and Root Solvers - Squarepoint (medium)
  • Solve two coding assessment tasks - Squarepoint (hard)
  • Parse payroll file and answer queries - Squarepoint (medium)
  • Maximize revenue from inventory sales - Squarepoint (medium)