PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Retool

Compute max profit with forced trades

Last updated: Mar 29, 2026

Quick Overview

This question evaluates algorithmic problem-solving in the Coding & Algorithms domain, focusing on array processing and constrained optimization for maximizing stock-trading profit under a forced-trade requirement for exactly one or two buy-sell transactions; it assesses state management, edge-case handling, and arithmetic reasoning.

  • Medium
  • Retool
  • Coding & Algorithms
  • Software Engineer

Compute max profit with forced trades

Company: Retool

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Technical Screen

Given an array prices where prices[i] is the stock price on day i, solve two related tasks under a forced-trade constraint: (a) Exactly one transaction: choose one buy day and one later sell day to maximize profit; if prices never rise, return the least possible loss that results from exactly one buy and one sell. (b) Exactly two transactions: choose two non-overlapping buy-sell pairs (sell before the next buy) to maximize total profit; if necessary, include losses so that exactly two transactions are performed. Implement two functions (e.g., profitExactlyOne(prices), profitExactlyTwo(prices)) and specify assumptions (single share per transaction; no transaction costs; cannot short). Handle edge cases (empty or single-element arrays). No explicit time-complexity requirement.

Quick Answer: This question evaluates algorithmic problem-solving in the Coding & Algorithms domain, focusing on array processing and constrained optimization for maximizing stock-trading profit under a forced-trade requirement for exactly one or two buy-sell transactions; it assesses state management, edge-case handling, and arithmetic reasoning.

Retool logo
Retool
Jul 26, 2025, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
8
0

Given an array prices where prices[i] is the stock price on day i, solve two related tasks under a forced-trade constraint: (a) Exactly one transaction: choose one buy day and one later sell day to maximize profit; if prices never rise, return the least possible loss that results from exactly one buy and one sell. (b) Exactly two transactions: choose two non-overlapping buy-sell pairs (sell before the next buy) to maximize total profit; if necessary, include losses so that exactly two transactions are performed. Implement two functions (e.g., profitExactlyOne(prices), profitExactlyTwo(prices)) and specify assumptions (single share per transaction; no transaction costs; cannot short). Handle edge cases (empty or single-element arrays). No explicit time-complexity requirement.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Retool•More Software Engineer•Retool Software Engineer•Retool Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,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.