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 Zero Cross

Learn
Play
Prove
Problem context and objectives
Mission briefing

Puzzle systems engineer · A game mechanic is behaving incorrectly

Use the first row and column as markers: The Zero Cross.

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

How you win

  1. 1Recognize when Set matrix zeroes matches the clues
  2. 2Keep this true after every move: marker cells record every interior row and column that must become zero
  3. 3Reach the result within O(rows times cols) time and O(1) extra space

Rules and pressure

  • Target cost: O(rows times cols) time and O(1) extra space
  • State rule: marker cells record every interior row and column that must become zero
Lesson 1 of 3

Live algorithm trace

Set matrix zeroes

Complete execution
1 of 5

Record whether the marker row or column already needs clearing.

1remember whether first row or column contains zero
2scan interior zeros
3mark their first-row column and first-column row
4zero marked interior cells
5zero first row and column if remembered
6return matrix
firstRowZero = falsefirstColZero = false
Truth to preserve / Cost target
Truth to preserve

marker cells record every interior row and column that must become zero

Cost target

O(rows times cols) time and O(1) extra space

A zero erases its full row and column. Store row and column markers in the matrix's first row and column, while remembering their original zero states separately.

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