Skip to content

Conversation

@WazedKhan
Copy link
Owner

@WazedKhan WazedKhan commented Jan 16, 2026

Summary by CodeRabbit

  • New Features
    • Added a solution that computes the largest possible square area obtainable by removing horizontal and vertical fences within an m×n field.
    • Returns -1 when no valid square exists; otherwise returns the square area (applies modulo 1,000,000,007).
    • Handles boundary conditions and documents expected inputs.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 16, 2026

📝 Walkthrough

Walkthrough

Introduces LeetCode/medium.py with a Solution class and maximizeSquareArea method that computes the largest square side formed by horizontal and vertical fence positions within an m×n field, returning the squared side length modulo 1,000,000,007 or -1 if none exists.

Changes

Cohort / File(s) Summary
New LeetCode Medium Problem
LeetCode/medium.py
Added Solution class with maximizeSquareArea(self, m: int, n: int, hFences: List[int], vFences: List[int]) -> int. Builds boundary-inclusive fence coordinate lists, computes horizontal distances, checks matching vertical distances, returns max side² % 1_000_000_007 or -1.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 I count the posts from end to start,
Distances dance and play their part.
Squares emerge where lines align,
I hop, I cheer — that side is mine! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: implementing a LeetCode solution (problem 2975) for finding the maximum square area by removing fences from a field.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

🧹 Recent nitpick comments
LeetCode/medium.py (2)

7-20: Move the misplaced comment.

The comment # Add boundaries on line 8 should be moved to line 21 where the boundary addition actually occurs. Per PEP 257, the docstring should be the first statement after the function definition.

✨ Suggested fix
     def maximizeSquareArea(self, m: int, n: int, hFences: List[int], vFences: List[int]) -> int:
-        # Add boundaries
         """
         This function calculates the maximum square area that can be formed by removing fences from a field of size m x n.

         Parameters:
         m (int): The width of the field
         n (int): The height of the field
         hFences (List[int]): A list of horizontal fence positions
         vFences (List[int]): A list of vertical fence positions

         Returns:
         int: The maximum square area that can be formed, or -1 if it is not possible
         """
+        # Add boundaries
         h = sorted([1] + hFences + [m])

21-22: Consider using list unpacking for cleaner syntax.

As flagged by Ruff (RUF005), unpacking is more idiomatic and slightly more efficient than concatenation.

✨ Suggested fix
-        h = sorted([1] + hFences + [m])
-        v = sorted([1] + vFences + [n])
+        h = sorted([1, *hFences, m])
+        v = sorted([1, *vFences, n])

📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 11f9604 and 1bc0ff2.

📒 Files selected for processing (1)
  • LeetCode/medium.py
🧰 Additional context used
🪛 Ruff (0.14.11)
LeetCode/medium.py

21-21: Consider [1, *hFences, m] instead of concatenation

Replace with [1, *hFences, m]

(RUF005)


22-22: Consider [1, *vFences, n] instead of concatenation

Replace with [1, *vFences, n]

(RUF005)

🔇 Additional comments (3)
LeetCode/medium.py (3)

1-6: LGTM!

The import and class structure are correct for the LeetCode solution.


24-35: LGTM!

The algorithm correctly finds the maximum common distance between fence positions in both directions. Using a set for horizontal distances enables efficient O(1) lookups during the vertical pass. The O(k²) complexity is acceptable given the problem constraints (k ≤ 602).


37-38: The modulo precedence issue has been correctly fixed.

The use of a named MOD constant properly addresses the operator precedence bug flagged in previous reviews. The expression now correctly computes (max_dist * max_dist) % (10**9 + 7).

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.


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

🤖 Fix all issues with AI agents
In `@LeetCode/medium.py`:
- Line 37: The return expression uses incorrect operator precedence causing
modulo to apply to 10**9 instead of 10**9+7; update the return in the function
where the current line is "return -1 if max_dist == 0 else (max_dist * max_dist)
% 10**9 + 7" to apply modulo correctly as (max_dist * max_dist) % (10**9 + 7)
(keeping the -1 when max_dist==0).
- Around line 24-35: The modulo expression around the squared maximum distance
is using wrong precedence; update the calculation that currently uses (max_dist
* max_dist) % 10**9 + 7 to apply the modulus correctly by parenthesizing the
modulus: use (max_dist * max_dist) % (10**9 + 7). Locate where max_dist is
squared and returned/used and replace the existing expression so the entire
modulus value 10**9 + 7 is grouped.
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b0ff36d and 11f9604.

📒 Files selected for processing (1)
  • LeetCode/medium.py
🧰 Additional context used
🪛 Ruff (0.14.11)
LeetCode/medium.py

21-21: Consider [1, *hFences, m] instead of concatenation

Replace with [1, *hFences, m]

(RUF005)


22-22: Consider [1, *vFences, n] instead of concatenation

Replace with [1, *vFences, n]

(RUF005)

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@WazedKhan WazedKhan merged commit 3678c9f into main Jan 16, 2026
3 checks passed
@WazedKhan WazedKhan deleted the 2975-max-sq-area-removing-fences-from-field branch January 16, 2026 05:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants