PracHub
QuestionsPremiumLearningGuidesInterview PrepNEWCoaches
|Home/Coding & Algorithms/Microsoft

Maximize profit with bounded sell window

Last updated: Mar 29, 2026

Quick Overview

This question evaluates proficiency in array algorithms, time and space complexity analysis, and techniques for bounded-range optimization and streaming adaptation.

  • Medium
  • Microsoft
  • Coding & Algorithms
  • Software Engineer

Maximize profit with bounded sell window

Company: Microsoft

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Onsite

Given an array prices[0..n-1] of daily stock prices and an integer D ≥ 1, you may perform at most one transaction (buy then sell). The sell day j must satisfy i < j ≤ min(i + D, n − 1) for the chosen buy day i. Return the maximum profit and the pair (i, j) achieving it; if no positive profit exists, return 0 and indicate that no transaction should be made. Design an O(n) time, O( 1) extra space algorithm, and discuss how you would adapt it for streaming input and for very large D.

Quick Answer: This question evaluates proficiency in array algorithms, time and space complexity analysis, and techniques for bounded-range optimization and streaming adaptation.

Related Interview Questions

  • Return Top K Open Businesses - Microsoft (hard)
  • Implement Memory Allocation and In-Memory Records - Microsoft (medium)
  • Implement K-Means and Detect Divisible Subarrays - Microsoft (medium)
  • Sort Three Categories In Place - Microsoft (medium)
  • Retain Top K Elements - Microsoft (medium)
Microsoft logo
Microsoft
Aug 14, 2025, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
5
0

Given an array prices[0..n-1] of daily stock prices and an integer D ≥ 1, you may perform at most one transaction (buy then sell). The sell day j must satisfy i < j ≤ min(i + D, n −

  1. for the chosen buy day i. Return the maximum profit and the pair (i, j) achieving it; if no positive profit exists, return 0 and indicate that no transaction should be made. Design an O(n) time, O(
  2. extra space algorithm, and discuss how you would adapt it for streaming input and for very large D.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Microsoft•More Software Engineer•Microsoft Software Engineer•Microsoft Coding & Algorithms•Software 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.