Home
Log in
DescriptionSubmissionsSolution
DescriptionSubmissionsSolution
Loading...

Log in to run or submit

matrix =

Codey

Practise coding problems, test your solutions and track your progress.

Explore

  • Problems
  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

© 2026 Codey. Personal learning project.

Solution
Updated: 2026-02-23

Idea

Use first row/col as markers to get O(1) extra space.

Approach

  • Record whether first row/col originally contain zero.
  • For each zero at (r,c) (excluding row0/col0), mark matrix[r][0]=0, matrix[0][c]=0.
  • Second pass: zero cells based on markers.
  • Finally zero first row/col if needed.
Code
Loading...
Complexity
Time: O(mn)
Space: O(1)
Solution
Updated: 2026-02-23

Idea

Use first row/col as markers to get O(1) extra space.

Approach

  • Record whether first row/col originally contain zero.
  • For each zero at (r,c) (excluding row0/col0), mark matrix[r][0]=0, matrix[0][c]=0.
  • Second pass: zero cells based on markers.
  • Finally zero first row/col if needed.
Code
Loading...
Complexity
Time: O(mn)
Space: O(1)