Skip to content

Conversation

@BrianLusina
Copy link
Owner

@BrianLusina BrianLusina commented Jan 14, 2026

Describe your change:

  • Top k and kth largest
  • 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.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.

Summary by CodeRabbit

  • New Features

    • Added top-K largest, kth-largest, K-closest-to-origin utilities and a Sudoku board validator.
  • Documentation

    • Added detailed READMEs with examples, approaches, complexity notes, and normalized image paths across several guides.
  • Tests

    • Added unit tests covering varied scenarios for new utilities (duplicates, different k values, multiple boards).
  • Chores

    • Removed several duplicate/obsolete puzzle entries and one deprecated listing.

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

@BrianLusina BrianLusina self-assigned this Jan 14, 2026
@BrianLusina BrianLusina added enhancement Algorithm Algorithm Problem Datastructures Datastructures Documentation Documentation Updates Sorting Contains sorting in the algorithm Array Array data structure Binary Tree Heap labels Jan 14, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 14, 2026

📝 Walkthrough

Walkthrough

Added new heap algorithm modules (Top K Largest, K Closest to Origin), a Sudoku validator, corresponding READMEs and unit tests; normalized several README image paths; renamed a local variable in Longest Happy String and updated its test import; DIRECTORY.md updated to reflect these changes.

Changes

Cohort / File(s) Summary
Documentation Index
DIRECTORY.md
Updated directory entries: added Heap items (Topkclosesttoorigin, Topklargest), Matrix IsvalidSudoku, adjusted Heap/puzzles listings and test links.
Top-K Largest (implementation & tests)
algorithms/heap/topklargest/__init__.py, algorithms/heap/topklargest/README.md, algorithms/heap/topklargest/test_top_k_largest_elements.py
New implementations: k_largest(nums, k=3), kth_largest(nums,k) (min-heap), kth_largest_sorting(nums,k); README with approaches/complexities; tests covering duplicates, various k, and invalid inputs. Check input validation conventions ([] / -1) and ordering of returned k elements.
K Closest to Origin (implementation & tests)
algorithms/heap/topkclosesttoorigin/__init__.py, algorithms/heap/topkclosesttoorigin/README.md, algorithms/heap/topkclosesttoorigin/test_top_k_closest_to_origin.py
New functions: k_closest_to_origin(points,k) (max-heap via negated distance) and k_closest_to_origin_sorting(points,k); README added; tests validate both implementations. Review k-bound handling and result ordering consistency.
Matrix — Valid Sudoku (implementation & tests)
algorithms/matrix/isvalidsudoku/__init__.py, algorithms/matrix/isvalidsudoku/README.md, algorithms/matrix/isvalidsudoku/test_is_valid_sudoku.py
New is_valid_sudoku(board: List[List[str]]) -> bool using row/col/box sets and 3x3 box indexing; README and parameterized tests added. Verify board-size validation and '.' (empty cell) handling.
Longest Happy String (small change & test import)
algorithms/heap/longest_happy_string/__init__.py, algorithms/heap/longest_happy_string/test_longest_happy_string.py, algorithms/heap/longest_happy_string/README.md
Local variable rename (countnegative_count with explicit negation) in implementation; test import path updated to algorithms.heap.longest_happy_string; README image path normalization. Confirm no behavioral change.
Minor README image path fixes
algorithms/heap/min_cost_to_connect_sticks/README.md, algorithms/heap/total_cost_hire_k_workers/README.md, algorithms/heap/longest_happy_string/README.md
Normalized image paths (removed leading ./) and minor formatting tweaks; no code changes.

Sequence Diagram(s)

(omitted — changes are library/algorithm additions and docs without multi-component sequential control flow requiring visualization)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~30 minutes

Possibly related PRs

Poem

🐇 I hopped through heaps to find the best,
Counted k and sorted out the rest.
Sudoku boxes neat and bright,
Docs aligned and tests take flight.
A tiny tweak — a rabbit’s delight 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 30.77% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately reflects the main changes: adding heap-based top k and kth largest algorithms. It is concise, specific, and clearly communicates the primary contribution.
Description check ✅ Passed The description covers the change (top k and kth largest), includes a complete checklist (though one item is not applicable), and demonstrates the author's understanding of contribution requirements. However, it lacks detail about the specific algorithms added and files modified.

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

✨ Finishing touches
  • 📝 Generate docstrings


📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 98018a8 and 39a67e0.

📒 Files selected for processing (1)
  • algorithms/matrix/isvalidsudoku/__init__.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • algorithms/matrix/isvalidsudoku/init.py

✏️ 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 `@algorithms/heap/topklargest/__init__.py`:
- Around line 72-76: The in-place call nums.sort(reverse=True) mutates the
caller's list; change it to operate on a non-mutating sorted sequence (e.g., use
sorted(nums, reverse=True) or sort a shallow copy) and then return the k-th
largest from that result (replace the nums.sort and return nums[k - 1] usage
with a non-mutating sorted result variable and return that_result[k - 1]);
ensure references to nums.sort(reverse=True) and the subsequent return are
updated accordingly.
- Around line 5-27: k_largest lacks input validation and can IndexError on empty
inputs or invalid k; add guards at the start of k_largest to validate params
(nums and k) consistent with the other variants: if not nums or k <= 0 or k >
len(nums) raise a ValueError with a clear message (e.g., "k must be between 1
and len(nums) and nums must be non-empty"); perform this validation before
building min_heap and iterating.
🧹 Nitpick comments (2)
algorithms/heap/topklargest/__init__.py (1)

30-56: Implementation is correct; consider exception vs sentinel for invalid input.

The heap-based algorithm is correctly implemented with O(n log k) time complexity. One consideration: returning -1 for invalid input could be ambiguous if -1 is a valid element in the array. An alternative would be to raise a ValueError, which is more Pythonic for invalid arguments. However, this is consistent with kth_largest_sorting, so the current approach is acceptable if documented.

algorithms/heap/topklargest/test_top_k_largest_elements.py (1)

6-27: Consider adding edge case tests for invalid inputs.

The current test cases cover happy paths well, but consider adding tests for:

  • Empty list: ([], 1, -1) for kth_largest/kth_largest_sorting
  • k=0: ([1,2,3], 0, -1)
  • k > len(nums): ([1,2], 5, -1)

This would validate the input validation logic and document expected behavior.

📝 Suggested additional test cases
KTH_LARGEST_EDGE_CASES = [
    ([], 1, -1),  # empty list
    ([1, 2, 3], 0, -1),  # k = 0
    ([1, 2], 5, -1),  # k > len(nums)
]
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6cb240c and 0f36bfc.

⛔ Files ignored due to path filters (16)
  • algorithms/heap/topklargest/images/solutions/kth_largest_element_in_array_solution_1.png is excluded by !**/*.png
  • algorithms/heap/topklargest/images/solutions/kth_largest_element_in_array_solution_10.png is excluded by !**/*.png
  • algorithms/heap/topklargest/images/solutions/kth_largest_element_in_array_solution_11.png is excluded by !**/*.png
  • algorithms/heap/topklargest/images/solutions/kth_largest_element_in_array_solution_2.png is excluded by !**/*.png
  • algorithms/heap/topklargest/images/solutions/kth_largest_element_in_array_solution_3.png is excluded by !**/*.png
  • algorithms/heap/topklargest/images/solutions/kth_largest_element_in_array_solution_4.png is excluded by !**/*.png
  • algorithms/heap/topklargest/images/solutions/kth_largest_element_in_array_solution_5.png is excluded by !**/*.png
  • algorithms/heap/topklargest/images/solutions/kth_largest_element_in_array_solution_6.png is excluded by !**/*.png
  • algorithms/heap/topklargest/images/solutions/kth_largest_element_in_array_solution_7.png is excluded by !**/*.png
  • algorithms/heap/topklargest/images/solutions/kth_largest_element_in_array_solution_8.png is excluded by !**/*.png
  • algorithms/heap/topklargest/images/solutions/kth_largest_element_in_array_solution_9.png is excluded by !**/*.png
  • algorithms/heap/topklargest/images/solutions/top_k_largest_element_in_array_solution_1.png is excluded by !**/*.png
  • algorithms/heap/topklargest/images/solutions/top_k_largest_element_in_array_solution_2.png is excluded by !**/*.png
  • algorithms/heap/topklargest/images/solutions/top_k_largest_element_in_array_solution_3.png is excluded by !**/*.png
  • algorithms/heap/topklargest/images/solutions/top_k_largest_element_in_array_solution_4.png is excluded by !**/*.png
  • algorithms/heap/topklargest/images/solutions/top_k_largest_element_in_array_solution_5.png is excluded by !**/*.png
📒 Files selected for processing (6)
  • DIRECTORY.md
  • algorithms/heap/topkfrequentelements/README.md
  • algorithms/heap/topkfrequentelements/__init__.py
  • algorithms/heap/topklargest/README.md
  • algorithms/heap/topklargest/__init__.py
  • algorithms/heap/topklargest/test_top_k_largest_elements.py
🧰 Additional context used
🧬 Code graph analysis (1)
algorithms/heap/topklargest/test_top_k_largest_elements.py (1)
algorithms/heap/topklargest/__init__.py (3)
  • k_largest (5-27)
  • kth_largest (30-56)
  • kth_largest_sorting (59-76)
🪛 LanguageTool
algorithms/heap/topklargest/README.md

[style] ~84-~84: Using many exclamation marks might seem excessive (in this case: 11 exclamation marks for a text that’s 3674 characters long)
Context: ...argest_element_in_array_solution_1.png) Solution 2.2 Solution 2.3 Solution 2.4 Solution 2.5 Solution 2.6 Solution 2.7 Solution 2.8 Solution 2.9 ![Solution 2.10](./images/solutions/kth_l...

(EN_EXCESSIVE_EXCLAMATION)

🪛 markdownlint-cli2 (0.18.1)
DIRECTORY.md

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

(MD007, ul-indent)


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

(MD007, ul-indent)

🔇 Additional comments (4)
algorithms/heap/topklargest/README.md (2)

1-46: Documentation is well-structured and accurate.

The explanation of the min-heap approach for Top-K elements is clear, with appropriate complexity analysis. The note about variable k complexity is helpful for understanding the general case.


49-106: LGTM!

The documentation for the Kth Largest Element problem is comprehensive, covering both sorting and min-heap approaches with accurate complexity analysis.

algorithms/heap/topklargest/test_top_k_largest_elements.py (1)

12-16: LGTM!

Good use of sorted() comparison for k_largest since the heap doesn't guarantee order within the result set.

DIRECTORY.md (1)

143-144: LGTM!

The new entry for Topklargest follows the existing indentation pattern in the file. The static analysis warning about indentation can be safely ignored as the style is consistent with other entries in the Heap section (e.g., Schedule Tasks on lines 141-142).

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

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: 3

🤖 Fix all issues with AI agents
In `@algorithms/heap/topkclosesttoorigin/__init__.py`:
- Around line 31-36: k_closest_to_origin_sorting currently mutates the input by
calling points.sort(); change it to avoid side effects by sorting a copy (use
sorted(points, key=...)) or by copying first (points_copy = list(points);
points_copy.sort(...)) and then return the first k from the sorted copy so the
original input remains unchanged, matching the non-mutating behavior of
k_closest_to_origin.

In `@algorithms/heap/topkclosesttoorigin/README.md`:
- Around line 6-8: The distance formula in the README is garbled; replace the
incorrect expression with correct mathematical notation: for distance from
origin use "sqrt(x² + y²)" (or "√(x² + y²)"), and for distance between two
points use "sqrt((x₁ - x₂)² + (y₁ - y₂)²)" (or "√((x₁ - x₂)² + (y₁ - y₂)²)"),
ensuring variable names match those used elsewhere in the doc (e.g., x,y and a,b
or x₁,y₁ and x₂,y₂) and remove the malformed `√(x1 - a2)2 + (y1 - b2)2` text.

In `@algorithms/heap/topkclosesttoorigin/test_top_k_closest_to_origin.py`:
- Around line 23-25: The test sorts results only by x-coordinate which can be
flaky when x values tie; update the sorting key in
test_top_k_closest_to_origin.py to use both coordinates (e.g., key that returns
a tuple of (x, y)) for sorted_expected and sorted_actual in the block using
sorted_expected/sorted_actual and apply the same change in
test_top_k_closest_to_origin_sorting so comparisons are deterministic.
🧹 Nitpick comments (1)
algorithms/heap/topkclosesttoorigin/__init__.py (1)

5-28: Consider adding edge case validation.

The heap-based implementation is correct and efficient. However, there's no validation for edge cases:

  • k <= 0 would return an empty list (acceptable but undocumented)
  • k > len(points) would return all points (acceptable)
  • Empty points list would return empty (acceptable)

These behaviors may be intentional, but documenting them or adding explicit validation would improve robustness.

🔧 Optional: Add input validation
 def k_closest_to_origin(points: List[List[int]], k: int) -> List[List[int]]:
+    if not points or k <= 0:
+        return []
+    k = min(k, len(points))
+
     # Max heap will store the top k points closest to the origin in the form (-distance, idx). The distance is negated
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0f36bfc and 2bb4e1f.

⛔ Files ignored due to path filters (13)
  • algorithms/heap/topkclosesttoorigin/images/examples/top_k_closest_to_origin_example_1.png is excluded by !**/*.png
  • algorithms/heap/topkclosesttoorigin/images/solutions/top_k_closest_to_origin_solution_0.png is excluded by !**/*.png
  • algorithms/heap/topkclosesttoorigin/images/solutions/top_k_closest_to_origin_solution_1.png is excluded by !**/*.png
  • algorithms/heap/topkclosesttoorigin/images/solutions/top_k_closest_to_origin_solution_10.png is excluded by !**/*.png
  • algorithms/heap/topkclosesttoorigin/images/solutions/top_k_closest_to_origin_solution_11.png is excluded by !**/*.png
  • algorithms/heap/topkclosesttoorigin/images/solutions/top_k_closest_to_origin_solution_2.png is excluded by !**/*.png
  • algorithms/heap/topkclosesttoorigin/images/solutions/top_k_closest_to_origin_solution_3.png is excluded by !**/*.png
  • algorithms/heap/topkclosesttoorigin/images/solutions/top_k_closest_to_origin_solution_4.png is excluded by !**/*.png
  • algorithms/heap/topkclosesttoorigin/images/solutions/top_k_closest_to_origin_solution_5.png is excluded by !**/*.png
  • algorithms/heap/topkclosesttoorigin/images/solutions/top_k_closest_to_origin_solution_6.png is excluded by !**/*.png
  • algorithms/heap/topkclosesttoorigin/images/solutions/top_k_closest_to_origin_solution_7.png is excluded by !**/*.png
  • algorithms/heap/topkclosesttoorigin/images/solutions/top_k_closest_to_origin_solution_8.png is excluded by !**/*.png
  • algorithms/heap/topkclosesttoorigin/images/solutions/top_k_closest_to_origin_solution_9.png is excluded by !**/*.png
📒 Files selected for processing (4)
  • DIRECTORY.md
  • algorithms/heap/topkclosesttoorigin/README.md
  • algorithms/heap/topkclosesttoorigin/__init__.py
  • algorithms/heap/topkclosesttoorigin/test_top_k_closest_to_origin.py
🧰 Additional context used
🧬 Code graph analysis (1)
algorithms/heap/topkclosesttoorigin/test_top_k_closest_to_origin.py (1)
algorithms/heap/topkclosesttoorigin/__init__.py (2)
  • k_closest_to_origin (5-28)
  • k_closest_to_origin_sorting (31-36)
🪛 LanguageTool
algorithms/heap/topkclosesttoorigin/README.md

[style] ~82-~82: Using many exclamation marks might seem excessive (in this case: 10 exclamation marks for a text that’s 3221 characters long)
Context: ...top_k_closest_to_origin_solution_0.png) Solution 1 Solution 2 Solution 3 Solution 4 Solution 5 Solution 6 Solution 7 Solution 8 Solution 9 ![Solution 10](./images/solutions/top_k_c...

(EN_EXCESSIVE_EXCLAMATION)

🪛 markdownlint-cli2 (0.18.1)
DIRECTORY.md

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

(MD007, ul-indent)


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

(MD007, ul-indent)


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

(MD007, ul-indent)


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

(MD007, ul-indent)

🔇 Additional comments (3)
DIRECTORY.md (1)

143-146: LGTM!

The new directory entries for Topkclosesttoorigin and Topklargest are correctly added and follow the existing indentation pattern used throughout the file. The static analysis hints about indentation (MD007) are false positives since the file consistently uses 4-space and 6-space indentation for nested list items.

algorithms/heap/topkclosesttoorigin/README.md (1)

56-104: LGTM!

The algorithm explanation and complexity analysis are well-written and accurate. The cross-reference to the related topklargest implementation provides helpful context.

algorithms/heap/topkclosesttoorigin/test_top_k_closest_to_origin.py (1)

9-13: Test coverage is adequate for core functionality.

The test cases cover the basic scenarios. Consider adding edge cases in future iterations:

  • k = 0
  • k > len(points)
  • Points with identical distances to origin

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

BrianLusina and others added 8 commits January 14, 2026 19:50
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
…in.py

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@github-actions
Copy link

github-actions bot commented Jan 15, 2026

Warnings
⚠️ ❗ Big PR

: Pull Request size seems relatively large. If Pull Request contains multiple changes, split each into separate PR will helps faster, easier review.

Generated by 🚫 dangerJS against 39a67e0

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: 1

🤖 Fix all issues with AI agents
In `@algorithms/matrix/isvalidsudoku/__init__.py`:
- Around line 15-20: The code only checks len(board) == 9 but not that each row
has 9 columns; update the validation in the isValidSudoku / is_valid_sudoku
implementation to iterate over board rows and return False if any len(row) != 9
before computing number_of_columns or indexing board[0]; this prevents malformed
inputs (e.g., short rows) from causing incorrect behavior or index errors.
🧹 Nitpick comments (3)
algorithms/matrix/isvalidsudoku/README.md (2)

1-26: Good documentation structure.

The problem statement is clear, constraints are well-defined, and examples are properly referenced.

Minor formatting issue on line 12: missing space after "Note:".

📝 Suggested fix
-> Note:A partially filled Sudoku board can be valid even if it is not necessarily solvable. You only need to verify that
+> Note: A partially filled Sudoku board can be valid even if it is not necessarily solvable. You only need to verify that

44-59: Minor inconsistency in variable naming.

The algorithm description uses row_sets, col_sets, box_sets (lines 44-46), but later references them as row_set, col_set, box_set (lines 56-58). Consider using consistent naming throughout.

📝 Suggested fix for consistency
-    - If no duplicate is found, we insert `cell` into:
-      - `row_set[r]`, 
-      - `col_set[c]`, 
-      - `box_set[box_idx]`.
+    - If no duplicate is found, we insert `cell` into:
+      - `row_sets[r]`, 
+      - `col_sets[c]`, 
+      - `box_sets[box_idx]`.
algorithms/matrix/isvalidsudoku/test_is_valid_sudoku.py (1)

6-77: Good test coverage for basic scenarios.

The test cases cover valid/invalid boards with row and column duplicates effectively. The parameterized approach is clean and maintainable.

Consider adding test cases for:

  • 3x3 box duplicates (a digit repeated within the same sub-box but not in same row/column)
  • Invalid board dimensions (e.g., 8x9 or empty board) to test the edge case validation in the implementation
  • Edge case with k > len(nums) scenario
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 90c4681 and 98018a8.

⛔ Files ignored due to path filters (60)
  • algorithms/heap/longest_happy_string/images/examples/longest_happy_string_example_1.png is excluded by !**/*.png
  • algorithms/heap/longest_happy_string/images/examples/longest_happy_string_example_2.png is excluded by !**/*.png
  • algorithms/heap/longest_happy_string/images/examples/longest_happy_string_example_3.png is excluded by !**/*.png
  • algorithms/heap/longest_happy_string/images/solutions/longest_happy_string_solution_1.png is excluded by !**/*.png
  • algorithms/heap/longest_happy_string/images/solutions/longest_happy_string_solution_10.png is excluded by !**/*.png
  • algorithms/heap/longest_happy_string/images/solutions/longest_happy_string_solution_11.png is excluded by !**/*.png
  • algorithms/heap/longest_happy_string/images/solutions/longest_happy_string_solution_12.png is excluded by !**/*.png
  • algorithms/heap/longest_happy_string/images/solutions/longest_happy_string_solution_13.png is excluded by !**/*.png
  • algorithms/heap/longest_happy_string/images/solutions/longest_happy_string_solution_14.png is excluded by !**/*.png
  • algorithms/heap/longest_happy_string/images/solutions/longest_happy_string_solution_15.png is excluded by !**/*.png
  • algorithms/heap/longest_happy_string/images/solutions/longest_happy_string_solution_2.png is excluded by !**/*.png
  • algorithms/heap/longest_happy_string/images/solutions/longest_happy_string_solution_3.png is excluded by !**/*.png
  • algorithms/heap/longest_happy_string/images/solutions/longest_happy_string_solution_4.png is excluded by !**/*.png
  • algorithms/heap/longest_happy_string/images/solutions/longest_happy_string_solution_5.png is excluded by !**/*.png
  • algorithms/heap/longest_happy_string/images/solutions/longest_happy_string_solution_6.png is excluded by !**/*.png
  • algorithms/heap/longest_happy_string/images/solutions/longest_happy_string_solution_7.png is excluded by !**/*.png
  • algorithms/heap/longest_happy_string/images/solutions/longest_happy_string_solution_8.png is excluded by !**/*.png
  • algorithms/heap/longest_happy_string/images/solutions/longest_happy_string_solution_9.png is excluded by !**/*.png
  • algorithms/heap/maximal_score_after_k_operations/images/examples/maximal_score_after_k_operations_example_1.png is excluded by !**/*.png
  • algorithms/heap/maximal_score_after_k_operations/images/examples/maximal_score_after_k_operations_example_2.png is excluded by !**/*.png
  • algorithms/heap/maximal_score_after_k_operations/images/examples/maximal_score_after_k_operations_example_3.png is excluded by !**/*.png
  • algorithms/heap/maximal_score_after_k_operations/images/solution/maximal_score_after_k_operations_solution_1.png is excluded by !**/*.png
  • algorithms/heap/maximal_score_after_k_operations/images/solution/maximal_score_after_k_operations_solution_10.png is excluded by !**/*.png
  • algorithms/heap/maximal_score_after_k_operations/images/solution/maximal_score_after_k_operations_solution_11.png is excluded by !**/*.png
  • algorithms/heap/maximal_score_after_k_operations/images/solution/maximal_score_after_k_operations_solution_12.png is excluded by !**/*.png
  • algorithms/heap/maximal_score_after_k_operations/images/solution/maximal_score_after_k_operations_solution_13.png is excluded by !**/*.png
  • algorithms/heap/maximal_score_after_k_operations/images/solution/maximal_score_after_k_operations_solution_14.png is excluded by !**/*.png
  • algorithms/heap/maximal_score_after_k_operations/images/solution/maximal_score_after_k_operations_solution_15.png is excluded by !**/*.png
  • algorithms/heap/maximal_score_after_k_operations/images/solution/maximal_score_after_k_operations_solution_2.png is excluded by !**/*.png
  • algorithms/heap/maximal_score_after_k_operations/images/solution/maximal_score_after_k_operations_solution_3.png is excluded by !**/*.png
  • algorithms/heap/maximal_score_after_k_operations/images/solution/maximal_score_after_k_operations_solution_4.png is excluded by !**/*.png
  • algorithms/heap/maximal_score_after_k_operations/images/solution/maximal_score_after_k_operations_solution_5.png is excluded by !**/*.png
  • algorithms/heap/maximal_score_after_k_operations/images/solution/maximal_score_after_k_operations_solution_6.png is excluded by !**/*.png
  • algorithms/heap/maximal_score_after_k_operations/images/solution/maximal_score_after_k_operations_solution_7.png is excluded by !**/*.png
  • algorithms/heap/maximal_score_after_k_operations/images/solution/maximal_score_after_k_operations_solution_8.png is excluded by !**/*.png
  • algorithms/heap/maximal_score_after_k_operations/images/solution/maximal_score_after_k_operations_solution_9.png is excluded by !**/*.png
  • algorithms/heap/min_cost_to_connect_sticks/images/examples/min_cost_to_connect_sticks_1.png is excluded by !**/*.png
  • algorithms/heap/min_cost_to_connect_sticks/images/examples/min_cost_to_connect_sticks_2.png is excluded by !**/*.png
  • algorithms/heap/min_cost_to_connect_sticks/images/examples/min_cost_to_connect_sticks_3.png is excluded by !**/*.png
  • algorithms/heap/min_cost_to_connect_sticks/images/examples/min_cost_to_connect_sticks_4.png is excluded by !**/*.png
  • algorithms/heap/total_cost_hire_k_workers/total_cost_hire_k_workers_step_1.png is excluded by !**/*.png
  • algorithms/heap/total_cost_hire_k_workers/total_cost_hire_k_workers_step_2.png is excluded by !**/*.png
  • algorithms/heap/total_cost_hire_k_workers/total_cost_hire_k_workers_step_3.png is excluded by !**/*.png
  • algorithms/heap/total_cost_hire_k_workers/total_cost_hire_k_workers_step_4.png is excluded by !**/*.png
  • algorithms/heap/total_cost_hire_k_workers/total_cost_hire_k_workers_step_5.png is excluded by !**/*.png
  • algorithms/matrix/isvalidsudoku/images/examples/is_valid_sudoku_example_1.png is excluded by !**/*.png
  • algorithms/matrix/isvalidsudoku/images/examples/is_valid_sudoku_example_2.png is excluded by !**/*.png
  • algorithms/matrix/isvalidsudoku/images/examples/is_valid_sudoku_example_3.png is excluded by !**/*.png
  • algorithms/matrix/isvalidsudoku/images/solutions/is_valid_sudoku_solution_1.png is excluded by !**/*.png
  • algorithms/matrix/isvalidsudoku/images/solutions/is_valid_sudoku_solution_10.png is excluded by !**/*.png
  • algorithms/matrix/isvalidsudoku/images/solutions/is_valid_sudoku_solution_11.png is excluded by !**/*.png
  • algorithms/matrix/isvalidsudoku/images/solutions/is_valid_sudoku_solution_12.png is excluded by !**/*.png
  • algorithms/matrix/isvalidsudoku/images/solutions/is_valid_sudoku_solution_2.png is excluded by !**/*.png
  • algorithms/matrix/isvalidsudoku/images/solutions/is_valid_sudoku_solution_3.png is excluded by !**/*.png
  • algorithms/matrix/isvalidsudoku/images/solutions/is_valid_sudoku_solution_4.png is excluded by !**/*.png
  • algorithms/matrix/isvalidsudoku/images/solutions/is_valid_sudoku_solution_5.png is excluded by !**/*.png
  • algorithms/matrix/isvalidsudoku/images/solutions/is_valid_sudoku_solution_6.png is excluded by !**/*.png
  • algorithms/matrix/isvalidsudoku/images/solutions/is_valid_sudoku_solution_7.png is excluded by !**/*.png
  • algorithms/matrix/isvalidsudoku/images/solutions/is_valid_sudoku_solution_8.png is excluded by !**/*.png
  • algorithms/matrix/isvalidsudoku/images/solutions/is_valid_sudoku_solution_9.png is excluded by !**/*.png
📒 Files selected for processing (25)
  • DIRECTORY.md
  • algorithms/dfs/__init__.py
  • algorithms/heap/longest_happy_string/README.md
  • algorithms/heap/longest_happy_string/__init__.py
  • algorithms/heap/longest_happy_string/test_longest_happy_string.py
  • algorithms/heap/maximal_score_after_k_operations/README.md
  • algorithms/heap/maximal_score_after_k_operations/__init__.py
  • algorithms/heap/maximal_score_after_k_operations/test_maximal_score.py
  • algorithms/heap/maximum_subsequence_score/README.md
  • algorithms/heap/maximum_subsequence_score/__init__.py
  • algorithms/heap/maximum_subsequence_score/test_max_subsequence_score.py
  • algorithms/heap/min_cost_hire_k_workers/README.md
  • algorithms/heap/min_cost_hire_k_workers/__init__.py
  • algorithms/heap/min_cost_hire_k_workers/test_min_cost_to_hire_workers.py
  • algorithms/heap/min_cost_to_connect_sticks/README.md
  • algorithms/heap/min_cost_to_connect_sticks/__init__.py
  • algorithms/heap/min_cost_to_connect_sticks/test_min_cost_connect_sticks.py
  • algorithms/heap/topklargest/__init__.py
  • algorithms/heap/total_cost_hire_k_workers/README.md
  • algorithms/heap/total_cost_hire_k_workers/__init__.py
  • algorithms/heap/total_cost_hire_k_workers/test_total_cost_hire_k_workers.py
  • algorithms/matrix/__init__.py
  • algorithms/matrix/isvalidsudoku/README.md
  • algorithms/matrix/isvalidsudoku/__init__.py
  • algorithms/matrix/isvalidsudoku/test_is_valid_sudoku.py
✅ Files skipped from review due to trivial changes (1)
  • algorithms/heap/min_cost_to_connect_sticks/README.md
🧰 Additional context used
🧬 Code graph analysis (3)
algorithms/matrix/isvalidsudoku/test_is_valid_sudoku.py (1)
algorithms/matrix/isvalidsudoku/__init__.py (1)
  • is_valid_sudoku (4-51)
algorithms/heap/longest_happy_string/test_longest_happy_string.py (1)
algorithms/heap/longest_happy_string/__init__.py (1)
  • longest_diverse_string (5-52)
algorithms/heap/topklargest/__init__.py (1)
algorithms/sorting/heapsort/__init__.py (1)
  • heapify (60-63)
🪛 LanguageTool
algorithms/heap/longest_happy_string/README.md

[style] ~58-~58: Using many exclamation marks might seem excessive (in this case: 14 exclamation marks for a text that’s 5371 characters long)
Context: ...ns/longest_happy_string_solution_1.png) Longest Happy String Solution 2 Longest Happy String Solution 3 Longest Happy String Solution 4 Longest Happy String Solution 5 Longest Happy String Solution 6 Longest Happy String Solution 7 Longest Happy String Solution 8 Longest Happy String Solution 9 Longest Happy String Solution 10 Longest Happy String Solution 11 Longest Happy String Solution 12 Longest Happy String Solution 13 ![Longest Happy String Solution 14](image...

(EN_EXCESSIVE_EXCLAMATION)

algorithms/heap/total_cost_hire_k_workers/README.md

[style] ~68-~68: This phrase might be redundant. Consider either removing or replacing the adjective ‘additional’.
Context: ...ire a worker from a section, we need to add an additional candidate to this section. Therefore, we need two...

(ADD_AN_ADDITIONAL)


[locale-violation] ~76-~76: In American English, ‘afterward’ is the preferred variant. ‘Afterwards’ is more commonly used in British English and other dialects.
Context: ...d with the other one from tail_workers. Afterwards, we need to refill head_workers with th...

(AFTERWARDS_US)

algorithms/matrix/isvalidsudoku/README.md

[style] ~3-~3: Consider removing “of” to be more concise
Context: ...s valid. A board is considered valid if all of the following conditions hold (considering ...

(ALL_OF_THE)


[style] ~8-~8: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...ontains the digits 1–9 at most once. - Each of the nine 3 × 3 sub-boxes contains th...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)


[style] ~61-~61: Using many exclamation marks might seem excessive (in this case: 11 exclamation marks for a text that’s 3993 characters long)
Context: ...lutions/is_valid_sudoku_solution_1.png) Example 2 Example 3 Example 4 Example 5 Example 6 Example 7 Example 8 Example 9 Example 10 ![Example 11](images/solutions/is_valid_s...

(EN_EXCESSIVE_EXCLAMATION)

🪛 markdownlint-cli2 (0.18.1)
DIRECTORY.md

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

(MD007, ul-indent)


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

(MD007, ul-indent)


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

(MD007, ul-indent)


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

(MD007, ul-indent)


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

(MD007, ul-indent)


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

(MD007, ul-indent)


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

(MD007, ul-indent)


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

(MD007, ul-indent)


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

(MD007, ul-indent)


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

(MD007, ul-indent)


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

(MD007, ul-indent)


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

(MD007, ul-indent)


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

(MD007, ul-indent)


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

(MD007, ul-indent)


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

(MD007, ul-indent)


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

(MD007, ul-indent)


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

(MD007, ul-indent)


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

(MD007, ul-indent)


192-192: Unordered list indentation
Expected: 0; Actual: 2

(MD007, ul-indent)


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

(MD007, ul-indent)


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

(MD007, ul-indent)

🔇 Additional comments (11)
algorithms/heap/total_cost_hire_k_workers/README.md (1)

61-86: LGTM!

The image path updates normalize the references consistently. The formatting changes look good.

algorithms/heap/longest_happy_string/README.md (1)

25-27: LGTM!

Image path normalization is consistent with other README files in this PR. The changes improve path consistency across the documentation.

Also applies to: 58-72

algorithms/heap/longest_happy_string/__init__.py (1)

23-24: Good refactor for clarity.

Renaming count to negative_count and explicitly converting with count = -negative_count makes the code more self-documenting. The variable name now clearly conveys that heap values are stored as negatives for max-heap simulation.

algorithms/heap/longest_happy_string/test_longest_happy_string.py (1)

3-3: LGTM!

Import path correctly updated to reflect the module's new location under algorithms.heap. The test cases provide good coverage including edge cases with zero counts and unbalanced character frequencies.

algorithms/matrix/isvalidsudoku/README.md (1)

74-99: LGTM!

The complexity analysis is correct. For a fixed 9×9 board, both time and space are O(1) since the number of operations and storage are bounded by constants.

DIRECTORY.md (1)

141-158: LGTM!

The new directory entries for the Heap algorithms (Longest Happy String, Maximal Score After K Operations, Topkclosesttoorigin, Topklargest, etc.) and the Matrix/Isvalidsudoku entry follow the existing file structure and indentation conventions consistently.

Note: The static analysis indentation warnings (MD007) are false positives—the indentation used here matches the established convention throughout the rest of the file.

Also applies to: 192-194

algorithms/matrix/isvalidsudoku/test_is_valid_sudoku.py (1)

80-88: LGTM!

The test class structure is clean with proper use of parameterized.expand for data-driven testing and appropriate type hints.

algorithms/matrix/isvalidsudoku/__init__.py (1)

25-51: LGTM!

The core validation logic is correct and efficient. The single-pass approach with hash sets for tracking duplicates in rows, columns, and 3x3 boxes is the standard O(1) space/time solution for this problem. The box index formula (row // 3) * 3 + (col // 3) correctly maps each cell to its sub-box.

algorithms/heap/topklargest/__init__.py (3)

5-34: LGTM! Input validation and edge case handling now in place.

The k_largest function correctly validates inputs, caps k to the array length, and uses a min-heap approach efficiently. The previous concerns about missing validation have been addressed.


37-63: LGTM!

The kth_largest function correctly maintains a min-heap of size k and returns the heap root as the kth largest element. Input validation is properly implemented.


66-83: LGTM! In-place mutation issue resolved.

The function now uses sorted() to create a new list instead of mutating the input. This addresses the previous concern about unexpected side effects on the caller's list.

✏️ 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>
@BrianLusina BrianLusina merged commit e6eb579 into main Jan 15, 2026
6 of 8 checks passed
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 Binary Tree Datastructures Datastructures Documentation Documentation Updates enhancement Heap Sorting Contains sorting in the algorithm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants