Skip to content

Conversation

@BrianLusina
Copy link
Owner

@BrianLusina BrianLusina commented Nov 11, 2025

Describe your change:

Adds an algorithm to sets all the values of an n*m matrix to zero if any value in a row or column is zero.

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation.

Summary by CodeRabbit

  • New Features

    • Added a matrix utility that zeroes entire rows and columns when any element is zero (in-place behavior preserved).
  • Documentation

    • Added README describing the problem, constraints and illustrative examples.
  • Tests

    • Added a test suite with five cases covering single zeros, multiple zeros, no-op and mixed scenarios.

@BrianLusina BrianLusina self-assigned this Nov 11, 2025
@BrianLusina BrianLusina added Algorithm Algorithm Problem Array Array data structure labels Nov 11, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 11, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Adds a new "Set Matrix Zero" feature: a public function that zeros matrix rows and columns in-place using first row/column markers, plus documentation and unit tests. No other codepaths were modified.

Changes

Cohort / File(s) Summary
Documentation
DIRECTORY.md, datastructures/arrays/matrix/settozero/README.md
Added directory entry and README describing the Set Matrix Zero problem, constraints, examples, and algorithm overview.
Implementation
datastructures/arrays/matrix/settozero/__init__.py
New public function set_matrix_zeros(mat: List[List[int]]) -> List[List[int]] that marks and zeros rows/columns in-place using the first row/column as markers; handles empty matrices and first-row/column edge cases; O(rows×cols) time, O(1) extra space.
Tests
datastructures/arrays/matrix/settozero/test_set_matrix_zero.py
New unittest module with five cases exercising single-zero propagation, no-op, multiple zeros, and mixed scenarios; includes test runner entry point.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant set_matrix_zeros
    participant Matrix

    Caller->>set_matrix_zeros: call(mat)
    set_matrix_zeros->>set_matrix_zeros: validate input (empty?)
    set_matrix_zeros->>Matrix: scan first row & first column for zeros
    note right of set_matrix_zeros: record flags for first row/col
    set_matrix_zeros->>Matrix: mark rows/cols by writing to first row/col
    set_matrix_zeros->>Matrix: zero interior cells based on markers
    set_matrix_zeros->>Matrix: zero first row if flagged
    set_matrix_zeros->>Matrix: zero first column if flagged
    set_matrix_zeros->>Caller: return modified matrix
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Review marker logic and order of operations in __init__.py (ensuring original first row/column flags are preserved before marking).
  • Validate edge-case handling for empty matrices and single-row/column matrices.
  • Verify test coverage in test_set_matrix_zero.py matches described scenarios.

Poem

🐰 I hopped through rows and columns wide,
Marked the places where zeros hide,
A gentle nudge—no extra space,
Rows and columns cleared with grace,
Hooray, the matrix sleeps—zeros inside.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat(arrays): set matrix zeroes' clearly and concisely describes the main change: adding a set matrix zeroes algorithm to the arrays module.
Description check ✅ Passed The PR description includes the required template sections, covers the main change, and confirms completion of all checklist items as per repository guidelines.

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 04d315f and 0b63041.

📒 Files selected for processing (2)
  • datastructures/arrays/matrix/settozero/README.md (1 hunks)
  • datastructures/arrays/matrix/settozero/__init__.py (1 hunks)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
DIRECTORY.md (1)

190-192: Consider adjusting markdown indentation for consistency.

The markdown linter flags the indentation here as non-standard (using 4/6/8 spaces instead of the expected 2/4/6). While this doesn't affect functionality, aligning with standard markdown conventions improves consistency.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9f5abb3 and 04d315f.

⛔ Files ignored due to path filters (3)
  • datastructures/arrays/matrix/settozero/images/set_matrix_zero_example_one.png is excluded by !**/*.png
  • datastructures/arrays/matrix/settozero/images/set_matrix_zero_example_three.png is excluded by !**/*.png
  • datastructures/arrays/matrix/settozero/images/set_matrix_zero_example_two.png is excluded by !**/*.png
📒 Files selected for processing (4)
  • DIRECTORY.md (1 hunks)
  • datastructures/arrays/matrix/settozero/README.md (1 hunks)
  • datastructures/arrays/matrix/settozero/__init__.py (1 hunks)
  • datastructures/arrays/matrix/settozero/test_set_matrix_zero.py (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
datastructures/arrays/matrix/settozero/test_set_matrix_zero.py (1)
datastructures/arrays/matrix/settozero/__init__.py (1)
  • set_matrix_zeros (4-55)
🪛 markdownlint-cli2 (0.18.1)
DIRECTORY.md

190-190: Unordered list indentation
Expected: 2; Actual: 4

(MD007, ul-indent)


191-191: Unordered list indentation
Expected: 4; Actual: 6

(MD007, ul-indent)


192-192: Unordered list indentation
Expected: 6; Actual: 8

(MD007, ul-indent)

🔇 Additional comments (3)
datastructures/arrays/matrix/settozero/__init__.py (2)

19-27: LGTM! Efficient edge case and marker detection.

The empty matrix check prevents issues with edge cases, and using any() with generator expressions for detecting zeros in the first row/column is memory-efficient.


29-53: Excellent O(1) space implementation!

The algorithm correctly implements the standard in-place solution by using the first row and column as markers. The three-phase approach (mark interior → apply to interior → handle boundaries) is the right way to avoid corrupting markers prematurely.

datastructures/arrays/matrix/settozero/test_set_matrix_zero.py (1)

5-34: Comprehensive test coverage!

The five test cases provide excellent coverage:

  • Single zero propagation (test_1, test_4)
  • No-op scenario with no zeros (test_2)
  • Multiple zeros with complex patterns (test_3, test_5)
  • Various matrix dimensions (3x3, 3x4, 5x5)

All expected outputs are correct.

@BrianLusina BrianLusina merged commit eb9734c into main Nov 11, 2025
4 of 7 checks passed
@BrianLusina BrianLusina deleted the feat/arrays-set-matrix-zeroes branch November 11, 2025 10:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Algorithm Algorithm Problem Array Array data structure

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants