Skip to content

Conversation

@BrianLusina
Copy link
Owner

@BrianLusina BrianLusina commented Nov 13, 2025

Describe your change:

Adds an additional alternative solution with tests to the course schedule algorithm problem

  • x ] 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 course-feasibility check and several alternative algorithm variants (new implementations for select problems).
  • Documentation
    • Expanded Course Schedule docs with multiple examples, clearer solution breakdowns, and explicit time/space complexity sections.
  • Tests
    • Added and expanded tests for course ordering/feasibility, new algorithm variants, cycles, and edge cases.
  • Chores
    • Bumped CI workflow action versions and applied broad formatting/styling cleanups across tests and modules.
@BrianLusina BrianLusina self-assigned this Nov 13, 2025
@BrianLusina BrianLusina added Algorithm Algorithm Problem Graph Graph data structures and algorithms Array Array data structure labels Nov 13, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 13, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Adds Course Schedule content and tests: a Kahn’s-algorithm can_finish function, expanded README with examples/solutions, DIRECTORY link, new unit tests for ordering and feasibility, plus CI action version bumps and several unrelated formatting tweaks across the repo.

Changes

Cohort / File(s) Summary
Directory update
DIRECTORY.md
Added new Algorithms > Fast And Slow: Graphs > Course Schedule entry linking to the course schedule example.
Course Schedule docs
algorithms/graphs/course_schedule/README.md
Extensive rewrite: added Examples 1–6, reorganized solution sections into Solution 1 (DFS) and Solution 2 (Kahn), clarified graph/edge semantics, added complexity subsections and image placeholders.
Course Schedule implementation
algorithms/graphs/course_schedule/__init__.py
Added public can_finish(num_courses: int, prerequisites: List[List[int]]) -> bool (Kahn’s algorithm) with in-degree tracking and queue; preserved existing find_order and updated imports.
Course Schedule tests
algorithms/graphs/course_schedule/test_course_schedule.py
New tests for find_order and can_finish, covering simple cases, chains, cycles, disconnected nodes, and consistency between functions.
CI workflow
.github/workflows/pre-commit.yml
Upgraded actions versions: actions/checkout v2 → v5 and actions/cache v2 → v4.
New/alternative algorithms
algorithms/fast_and_slow/happy_number/__init__.py, algorithms/two_pointers/sort_colors/__init__.py, pystrings/permutation/__init__.py
Added is_happy_number_2 (fast/slow), sort_colors_v2 (two-pointer variant), and check_permutation_with_map (frequency-map permutation check).
Formatting/style-only edits
Multiple test and implementation files (e.g., many test_*.py, various __init__.py files across algorithms, datastructures, puzzles, pystrings)
Widespread cosmetic changes: whitespace, string quote normalization, blank-line adjustments, minor signature reflows—no behavior changes in those files.

Sequence Diagram(s)

sequenceDiagram participant Caller as User/Test participant can_finish as can_finish() participant Graph as AdjacencyList participant Queue as ZeroInDegreeQueue Caller->>can_finish: call(num_courses, prerequisites) can_finish->>Graph: build adjacency list & compute in-degrees can_finish->>Queue: enqueue nodes with in-degree == 0 rect rgb(235, 248, 235) loop process queue Queue->>can_finish: pop node u can_finish->>Graph: for neighbor in Graph[u] can_finish->>Graph: decrement in-degree[neighbor] alt in-degree[neighbor] == 0 can_finish->>Queue: enqueue neighbor end end end alt processed_count == num_courses can_finish->>Caller: return True else can_finish->>Caller: return False end 
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Pay attention to edge cases in can_finish (num_courses == 0, disconnected nodes, duplicate prerequisites).
  • Validate tests’ assertions for both cycle detection and valid order acceptance.
  • Quick skim of README examples vs. implementation to ensure consistency.

Possibly related PRs

Poem

🐰 A rabbit hops through graphs so neat,
Counting in-degrees with quick little feet.
DFS and Kahn dance in orderly rows,
Tests cheer loudly as each course goes.
Hooray — schedules sorted, every path complete!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title check ❓ Inconclusive The title 'feat(algorithms graphs): course schedule' is vague and overly broad, using generic terms that don't convey specific information about what was actually changed or added to the course schedule algorithm. Consider using a more specific title like 'feat(algorithms/graphs): add BFS-based solution to course schedule' or 'feat(algorithms/graphs): add can_finish function with tests to course schedule' to better describe the primary change.
✅ Passed checks (1 passed)
Check name Status Explanation
Description check ✅ Passed The PR description is mostly complete with all required checklist sections present and mostly checked, though there is a formatting error in the first checkbox and the description could be more detailed about specific changes.

📜 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 396709a and 5a5d7a1.

📒 Files selected for processing (80)
  • README.md (1 hunks)
  • algorithms/arrays/intersection/intersection_two.py (2 hunks)
  • algorithms/arrays/non_constructible_change/test_non_constructible_change.py (1 hunks)
  • algorithms/arrays/optimal_task_assignment/test_optimal_task_assignment.py (1 hunks)
  • algorithms/arrays/sorted_squared_array/__init__.py (2 hunks)
  • algorithms/arrays/sorted_squared_array/test_sorted_squared_array.py (2 hunks)
  • algorithms/arrays/subsequence/__init__.py (1 hunks)
  • algorithms/arrays/subsequence/test_is_valid_subsequence.py (2 hunks)
  • algorithms/fast_and_slow/circular_array_loop/test_circular_array_loop.py (2 hunks)
  • algorithms/fast_and_slow/find_duplicate/test_find_duplicate.py (3 hunks)
  • algorithms/fast_and_slow/happy_number/__init__.py (1 hunks)
  • algorithms/fast_and_slow/happy_number/test_happy_number.py (2 hunks)
  • algorithms/graphs/course_schedule/__init__.py (1 hunks)
  • algorithms/graphs/course_schedule/test_course_schedule.py (1 hunks)
  • algorithms/josephus_circle/test_josephus_circle.py (1 hunks)
  • algorithms/sliding_window/repeated_dna_sequences/__init__.py (3 hunks)
  • algorithms/sliding_window/repeated_dna_sequences/test_repeated_dna_sequences.py (4 hunks)
  • algorithms/two_pointers/find_sum_of_three/__init__.py (1 hunks)
  • algorithms/two_pointers/find_sum_of_three/test_find_sum_of_three.py (1 hunks)
  • algorithms/two_pointers/pair_with_sum_in_array/test_pair_with_sum_in_array.py (1 hunks)
  • algorithms/two_pointers/reverse_array/test_reverse_array.py (1 hunks)
  • algorithms/two_pointers/sort_colors/__init__.py (1 hunks)
  • algorithms/two_pointers/sort_colors/test_sort_colors.py (6 hunks)
  • datastructures/arrays/arbitrary_precision_increment/test_arbitrary_precision_increment.py (1 hunks)
  • datastructures/arrays/array_advance_game/test_array_advance_game.py (1 hunks)
  • datastructures/arrays/matrix/settozero/__init__.py (1 hunks)
  • datastructures/arrays/matrix/settozero/test_set_matrix_zero.py (1 hunks)
  • datastructures/arrays/subarrays_with_fixed_bounds/test_subarrays_with_fixed_bounds.py (1 hunks)
  • datastructures/linked_lists/__init__.py (1 hunks)
  • datastructures/linked_lists/circular/__init__.py (0 hunks)
  • datastructures/linked_lists/circular/node.py (1 hunks)
  • datastructures/linked_lists/circular/test_circular_linked_list.py (1 hunks)
  • datastructures/linked_lists/doubly_linked_list/__init__.py (0 hunks)
  • datastructures/linked_lists/doubly_linked_list/node.py (1 hunks)
  • datastructures/linked_lists/mergeklinkedlists/__init__.py (1 hunks)
  • datastructures/linked_lists/mergeklinkedlists/test_merge.py (2 hunks)
  • datastructures/linked_lists/singly_linked_list/__init__.py (1 hunks)
  • datastructures/linked_lists/singly_linked_list/test_singly_linked_list_remove_nth_last_node.py (4 hunks)
  • datastructures/linked_lists/singly_linked_list/test_singly_linked_palindrome.py (9 hunks)
  • datastructures/trees/__init__.py (1 hunks)
  • datastructures/trees/binary/node.py (1 hunks)
  • datastructures/trees/binary/search_tree/__init__.py (6 hunks)
  • datastructures/trees/binary/search_tree/test_binary_search_tree_insert.py (2 hunks)
  • datastructures/trees/binary/tree/__init__.py (7 hunks)
  • datastructures/trees/binary/tree/test_binary_tree.py (9 hunks)
  • puzzles/arrays/maxlen_contiguous_binary_subarray/test_maxlen_contiguous_binary_subarray.py (1 hunks)
  • puzzles/arrays/tournament_winner/test_tournament_winner.py (2 hunks)
  • puzzles/permutations_check/__init__.py (1 hunks)
  • puzzles/permutations_check/test_check.py (1 hunks)
  • puzzles/product_of_two_positive_integers/__init__.py (1 hunks)
  • puzzles/product_of_two_positive_integers/test_recursive_multiply.py (1 hunks)
  • puzzles/search/binary_search/cyclically_shifted_array/__init__.py (1 hunks)
  • puzzles/search/binary_search/cyclically_shifted_array/test_cyclically_shifted_array.py (1 hunks)
  • puzzles/search/binary_search/find_closest_number/test_find_closest_number.py (1 hunks)
  • puzzles/search/binary_search/find_closest_value/test_find_closest_value.py (1 hunks)
  • puzzles/search/binary_search/find_first_in_duplicate_list/__init__.py (4 hunks)
  • puzzles/search/binary_search/find_first_in_duplicate_list/test_find_first_in_duplicates.py (2 hunks)
  • puzzles/search/binary_search/find_fixed_number/test_find_fixed_number.py (1 hunks)
  • puzzles/search/binary_search/integer_square_root/test_integer_square_root.py (1 hunks)
  • puzzles/stack/decimal_to_binary/test_decimal_to_binary.py (1 hunks)
  • puzzles/stack/reverse_string/test_reverse_string.py (1 hunks)
  • pystrings/anagram/__init__.py (0 hunks)
  • pystrings/anagram/group_anagrams/__init__.py (2 hunks)
  • pystrings/anagram/group_anagrams/test_group_anagrams.py (2 hunks)
  • pystrings/count_consonants/__init__.py (1 hunks)
  • pystrings/count_consonants/test_count_consonants.py (2 hunks)
  • pystrings/inttostr/__init__.py (3 hunks)
  • pystrings/inttostr/test_int_to_str.py (1 hunks)
  • pystrings/is_unique/test_is_unique.py (1 hunks)
  • pystrings/look_and_say_sequence/__init__.py (1 hunks)
  • pystrings/look_and_say_sequence/test_look_and_say_sequence.py (1 hunks)
  • pystrings/palindrome/permutation_palindrome/test_permutation_palindrome.py (1 hunks)
  • pystrings/permutation/__init__.py (1 hunks)
  • pystrings/permutation/test_check_permutation.py (1 hunks)
  • pystrings/spreadsheet_encoding/__init__.py (1 hunks)
  • pystrings/spreadsheet_encoding/test_spreadsheet_encode.py (1 hunks)
  • pystrings/string_length/__init__.py (2 hunks)
  • pystrings/string_length/test_string_length.py (1 hunks)
  • pystrings/strtoint/__init__.py (2 hunks)
  • pystrings/strtoint/test_string_to_int.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

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1005257 and 617ab62.

⛔ Files ignored due to path filters (9)
  • algorithms/graphs/course_schedule/images/solution_2_slide_1.png is excluded by !**/*.png
  • algorithms/graphs/course_schedule/images/solution_2_slide_2.png is excluded by !**/*.png
  • algorithms/graphs/course_schedule/images/solution_2_slide_3.png is excluded by !**/*.png
  • algorithms/graphs/course_schedule/images/solution_2_slide_4.png is excluded by !**/*.png
  • algorithms/graphs/course_schedule/images/solution_2_slide_5.png is excluded by !**/*.png
  • algorithms/graphs/course_schedule/images/solution_2_slide_6.png is excluded by !**/*.png
  • algorithms/graphs/course_schedule/images/solution_2_slide_7.png is excluded by !**/*.png
  • algorithms/graphs/course_schedule/images/solution_2_slide_8.png is excluded by !**/*.png
  • algorithms/graphs/course_schedule/images/solution_2_slide_9.png is excluded by !**/*.png
📒 Files selected for processing (4)
  • DIRECTORY.md (1 hunks)
  • algorithms/graphs/course_schedule/README.md (3 hunks)
  • algorithms/graphs/course_schedule/__init__.py (1 hunks)
  • algorithms/graphs/course_schedule/test_course_schedule.py (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
algorithms/graphs/course_schedule/__init__.py (1)
datastructures/graphs/__init__.py (2)
  • topological_sorted_order (61-112)
  • dfs (84-105)
algorithms/graphs/course_schedule/test_course_schedule.py (1)
algorithms/graphs/course_schedule/__init__.py (2)
  • find_order (9-73)
  • can_finish (76-127)
🪛 LanguageTool
algorithms/graphs/course_schedule/README.md

[grammar] ~62-~62: Use a hyphen to join words.
Context: ...-- ## Solution 1 Breakdown (Using Depth First Search) Suppose we are at a node ...

(QB_NEW_EN_HYPHEN)


[style] ~147-~147: Consider removing “of” to be more concise
Context: ...ty will be O(V+E) because we’re storing all of the edges for each vertex in an adjacency l...

(ALL_OF_THE)

🪛 markdownlint-cli2 (0.18.1)
DIRECTORY.md

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

(MD007, ul-indent)


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

(MD007, ul-indent)


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

(MD007, ul-indent)

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

🧹 Nitpick comments (1)
.github/workflows/pre-commit.yml (1)

9-10: Verify action version upgrades for compatibility.

The checkout and cache actions have been upgraded to newer major versions (v2→v5 and v2→v4 respectively). Ensure these upgrades don't introduce breaking changes with the current cache configuration on lines 12-15.

Additionally, consider upgrading actions/setup-python@v2 on line 16 to a newer version for consistency, as it's now the only outdated action in this workflow (currently at v2 while others are at v4-v5).

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 617ab62 and 396709a.

📒 Files selected for processing (1)
  • .github/workflows/pre-commit.yml (1 hunks)
@BrianLusina BrianLusina merged commit b78b639 into main Nov 13, 2025
4 of 7 checks passed
@BrianLusina BrianLusina deleted the feat/algorithms-graphs-course-schedule branch November 13, 2025 07:09
@github-actions
Copy link

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 5a5d7a1

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 Graph Graph data structures and algorithms

2 participants