Skip to content

Phase-02: Linked-List#141

Merged
WazedKhan merged 6 commits into
mainfrom
phase-02-linked-list
Jul 4, 2026
Merged

Phase-02: Linked-List#141
WazedKhan merged 6 commits into
mainfrom
phase-02-linked-list

Conversation

@WazedKhan

@WazedKhan WazedKhan commented Jul 3, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features
    • Added linked-list cycle detection to determine whether a list contains a loop.
    • Added support utilities for linked lists, including computing list length.
    • Added the ability to remove the Nth node from the end of a linked list.
    • Added an in-place list reordering capability that rearranges nodes by alternating from the two halves.
    • Existing practice helpers remain available, including reversing a linked list, merging two sorted linked lists, and printing node values for quick inspection.

@WazedKhan WazedKhan self-assigned this Jul 3, 2026
@WazedKhan WazedKhan added the Katas label Jul 3, 2026
@coderabbitai

coderabbitai Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5274f366-0d68-4684-b47a-ad6f2b2818f7

📥 Commits

Reviewing files that changed from the base of the PR and between faf9822 and e1c7e23.

📒 Files selected for processing (1)
  • prep/practice/linked_list.py

📝 Walkthrough

Walkthrough

Updates prep/practice/linked_list.py with linked-list helpers, iterative reverse and merge operations, cycle detection, list length calculation, removal of the nth node from the end, and in-place list reordering.

Changes

Linked List Utilities

Layer / File(s) Summary
ListNode structure and traversal helper
prep/practice/linked_list.py
Defines ListNode and print_list(head) for linked-list traversal and output.
Reverse and merge solutions
prep/practice/linked_list.py
Implements Solution.reverseList and Solution.mergeTwoLists for in-place reversal and sorted-list merging.
Cycle detection and length helpers
prep/practice/linked_list.py
Adds Solution.hasCycle and Solution.list_len for cycle detection and node counting.
Remove nth from end
prep/practice/linked_list.py
Adds Solution.removeNthFromEnd using list length and a dummy head to remove the target node.
Reorder list
prep/practice/linked_list.py
Adds Solution.reorderList to split the list, reverse the second half, and merge nodes alternately.

Estimated code review effort: 2 (Simple) | ~15 minutes

Possibly related PRs

  • WazedKhan/Problems#140: Both PRs add an in-place reorderList(head) implementation with the same midpoint, reverse, and alternating merge flow.

Suggested labels: Medium

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title is related to linked-list work, but it is too generic to describe the actual change. Use a more specific title such as 'Add linked-list reorder operation' or 'Implement reorderList in linked-list practice code.'
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch phase-02-linked-list

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
prep/practice/linked_list.py (1)

4-7: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Builtin shadowing is fine here — matches standard LeetCode signature.

Ruff flags next shadowing the builtin, but this mirrors the canonical ListNode definition used across LeetCode problems, so renaming would reduce familiarity for this kata. No action needed.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@prep/practice/linked_list.py` around lines 4 - 7, No code change is needed
here: the ListNode.__init__ signature intentionally uses next to match the
standard LeetCode ListNode API, so keep the builtin-shadowing parameter name
unchanged and leave the class definition as-is.

Source: Linters/SAST tools

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@prep/practice/linked_list.py`:
- Around line 4-7: No code change is needed here: the ListNode.__init__
signature intentionally uses next to match the standard LeetCode ListNode API,
so keep the builtin-shadowing parameter name unchanged and leave the class
definition as-is.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0090d1e7-d25a-425d-a715-8a52c451501a

📥 Commits

Reviewing files that changed from the base of the PR and between e153484 and c342d89.

📒 Files selected for processing (1)
  • prep/practice/linked_list.py

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
prep/practice/linked_list.py (1)

69-78: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Unguarded edge case: empty list or n >= length can crash.

If head is None, or n equals/exceeds the list length, pos becomes <= 0, current stays at dummy, and current.next can be None — so current.next.next raises AttributeError. This matches LeetCode's constraint 1 <= n <= sz, so it won't trigger under the canonical problem constraints, but the method has no guard if reused elsewhere.

🛡️ Optional defensive guard
     def removeNthFromEnd(self, head: Optional[ListNode], n: int) -> Optional[ListNode]:
         pos = self.list_len(head) - n
+        if pos < 0:
+            return head
         dummy = ListNode(0)
         dummy.next = head
         current = dummy
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@prep/practice/linked_list.py` around lines 69 - 78, The removeNthFromEnd
method in linked_list.py has no defensive handling for an empty list or for n
being greater than or equal to the list length, which can make current.next None
and crash when accessing current.next.next. Add a guard in removeNthFromEnd
(using list_len and the dummy/current traversal) to return safely or no-op when
head is None or when the computed position is invalid before unlinking the node.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@prep/practice/linked_list.py`:
- Around line 69-78: The removeNthFromEnd method in linked_list.py has no
defensive handling for an empty list or for n being greater than or equal to the
list length, which can make current.next None and crash when accessing
current.next.next. Add a guard in removeNthFromEnd (using list_len and the
dummy/current traversal) to return safely or no-op when head is None or when the
computed position is invalid before unlinking the node.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 26b0d225-6c02-4f4a-a430-42ed53e27604

📥 Commits

Reviewing files that changed from the base of the PR and between 05eab5e and faf9822.

📒 Files selected for processing (1)
  • prep/practice/linked_list.py

@WazedKhan WazedKhan merged commit 259df76 into main Jul 4, 2026
2 of 3 checks passed
@WazedKhan WazedKhan deleted the phase-02-linked-list branch July 4, 2026 05:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant