Skip to content
playdsa
Preferences

Make yourself comfortable.

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

Theme
Advanced settings

Boss fightThe Rope Foundry

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 Rope Foundry.

A stale priority frontier increases wait time for everyone.

How you win

  1. 1Recognize when Optimal merge min-heap matches the clues
  2. 2Keep this true after every move: the heap contains exactly the current unmerged rope lengths
  3. 3Reach the result within O(n log n)

Rules and pressure

  • Target cost: O(n log n)
  • State rule: the heap contains exactly the current unmerged rope lengths
Lesson 1 of 3

Live algorithm trace

Optimal merge min-heap

Complete execution
1 of 6
2
root
3
4
6

Heapify four rope lengths so the shortest is always exposed.

1heapify all rope lengths
2while more than one rope remains
3pop two shortest
4join them and add to total cost
5push the joined rope
6return total
heap = [2,3,4,6]total = 0
Truth to preserve / Cost target
Truth to preserve

the heap contains exactly the current unmerged rope lengths

Cost target

O(n log n)

Every joined length may be paid again in later joins. Combining the two shortest ropes first keeps repeatedly charged intermediate lengths as small as possible.

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