Skip to content
playdsa
Preferences

Make yourself comfortable.

Saved on this browser. Your device’s reduced-motion preference is always respected.

Theme
Advanced settings

The Capital Engine

Learn
Play
Prove
Problem context and objectives
Mission briefing

Matchmaking coordinator · Urgent players and jobs compete for limited slots

Keep the best next candidate available without sorting everything again: The Capital Engine.

A stale priority frontier increases wait time for everyone.

How you win

  1. 1Recognize when Two-priority project selection matches the clues
  2. 2Keep this true after every move: the profit heap contains every unchosen project affordable with current capital
  3. 3Reach the result within O(n log n + k log n)

Rules and pressure

  • Target cost: O(n log n + k log n)
  • State rule: the profit heap contains every unchosen project affordable with current capital
Lesson 1 of 3

Live algorithm trace

Two-priority project selection

Complete execution
1 of 6
c0:p1
project
c1:p2
c1:p3

Sort projects by the capital required to start them.

1sort projects by required capital
2repeat at most k times
3push every newly affordable profit
4stop if no project is affordable
5pop maximum profit
6add profit to capital
7return capital
capital = 0k = 2sorted = 0,1,1
Truth to preserve / Cost target
Truth to preserve

the profit heap contains every unchosen project affordable with current capital

Cost target

O(n log n + k log n)

Sort projects by required capital and move every currently affordable project into a max-heap of profits. Choosing the greatest available profit can only expand the set affordable next.

Your call · What should guide every step of this algorithm?

Help shape PlayDSA

Something confusing, broken, or missing? Leave a quick note without leaving your lesson.

Please leave out passwords, payment details and other private information.

Page included: /

Sign in to save feedback here, or send it with your email app. Your draft stays here while you sign in.

Open email instead