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 New Bridge

Learn
Play
Prove
Problem context and objectives
Mission briefing

Puzzle systems engineer · A game mechanic is behaving incorrectly

Insert one span into ordered territory: The New Bridge.

Brute force may pass the demo but fail when the world fills with players.

How you win

  1. 1Recognize when Insert and merge intervals matches the clues
  2. 2Keep this true after every move: the output is sorted and nonoverlapping, and the live interval covers every absorbed overlap
  3. 3Reach the result within O(n)

Rules and pressure

  • Target cost: O(n)
  • State rule: the output is sorted and nonoverlapping, and the live interval covers every absorbed overlap
Lesson 1 of 3

Live algorithm trace

Insert and merge intervals

Complete execution
1 of 6

Copy 1-2 because it ends before the new interval begins.

1copy intervals ending before new start
2merge every overlapping interval
3append the merged interval
4copy intervals starting after new end
5return output
newInterval = 4-8output = [1-2]
Truth to preserve / Cost target
Truth to preserve

the output is sorted and nonoverlapping, and the live interval covers every absorbed overlap

Cost target

O(n)

Sorted nonoverlapping intervals split into three regions: spans before the new interval, spans that overlap it, and spans after it. Copy, absorb, then finish.

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