Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Stock Trading Profit Maximization
00:00
5 left

Stock Trading Profit Maximization

HardPython

Problem

Given a list of stock amounts and their profits and an initial budget to buy stocks, maximize total profit (solvable with a priority queue).

Asked in the Round 2 - DSA / Problem Solving stage. Candidate realized only afterward that a priority queue was the intended optimal approach; the interviewer was described as non-interactive, making the problem statement hard to clarify.

Implement maximize_profit(k, initial_budget, capital, profits). Each project requires the corresponding capital[i], returns profits[i], and can be selected at most once. Return the final budget after selecting at most k affordable projects. A project is affordable when its capital requirement is at most the current budget, and its profit is added immediately.

Constraints

  • 0 <= k <= len(capital)
  • 1 <= len(capital) = len(profits) <= 10^5
  • 0 <= initial_budget <= 10^9
  • 0 <= capital[i], profits[i] <= 10^9
  • Each project can be selected at most once

Function Signature

def maximize_profit(k, initial_budget, capital, profits):
Interviewer

Your question is Stock Trading Profit Maximization. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.