-
Notifications
You must be signed in to change notification settings - Fork 2
feat(algorithms, two-pointers): next permutation #125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughThe pull request reorganizes the Next Permutation problem from Puzzles to Algorithms > Two Pointers, updates the directory structure, adds comprehensive documentation, refactors the implementation with helper functions and detailed comments, and updates corresponding test imports. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~15 minutes
Suggested labels
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
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. Comment |
There was a problem hiding this 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
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
algorithms/two_pointers/next_permutation/__init__.py (1)
40-44: Add missing type annotation for consistency.The parameter
jis missing its type annotation, which is inconsistent with the rest of the codebase where all function parameters have type hints.🔎 Proposed fix
-def swap(nums: List[int], i: int, j) -> None: +def swap(nums: List[int], i: int, j: int) -> None:
🧹 Nitpick comments (1)
algorithms/two_pointers/next_permutation/README.md (1)
16-42: Consider adding language specifiers to code blocks.The example code blocks would benefit from language specifiers for better rendering and syntax highlighting in markdown viewers.
🔎 Proposed fix
-``` +```text Example 1: Input: nums = [1,2,3] Output: [1,3,2]-
+text
Example 2:Input: nums = [3,2,1]
Output: [1,2,3]-``` +```text Example 3: Input: nums = [1,1,5] Output: [1,5,1]-
+text
Example 4:Input: nums = [1]
Output: [1]
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
DIRECTORY.mdalgorithms/two_pointers/next_permutation/README.mdalgorithms/two_pointers/next_permutation/__init__.pyalgorithms/two_pointers/next_permutation/test_next_permutation.pypuzzles/next_permutation/README.md
💤 Files with no reviewable changes (1)
- puzzles/next_permutation/README.md
🧰 Additional context used
🧬 Code graph analysis (1)
algorithms/two_pointers/next_permutation/test_next_permutation.py (1)
algorithms/two_pointers/next_permutation/__init__.py (1)
next_permutation(4-26)
🪛 LanguageTool
algorithms/two_pointers/next_permutation/README.md
[style] ~55-~55: Consider a more expressive alternative.
Context: ...e array (the right-hand side) first. To do this, we make the smallest possible in...
(DO_ACHIEVE)
🪛 markdownlint-cli2 (0.18.1)
DIRECTORY.md
159-159: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
160-160: Unordered list indentation
Expected: 4; Actual: 6
(MD007, ul-indent)
algorithms/two_pointers/next_permutation/README.md
16-16: Fenced code blocks should have a language specified
(MD040, fenced-code-language)
23-23: Fenced code blocks should have a language specified
(MD040, fenced-code-language)
30-30: Fenced code blocks should have a language specified
(MD040, fenced-code-language)
37-37: Fenced code blocks should have a language specified
(MD040, fenced-code-language)
🔇 Additional comments (4)
algorithms/two_pointers/next_permutation/test_next_permutation.py (1)
3-3: LGTM! Import path correctly updated.The import path has been properly updated to reflect the reorganization of the Next Permutation functionality from
puzzlestoalgorithms.two_pointers. The test suite remains comprehensive and unchanged.algorithms/two_pointers/next_permutation/__init__.py (2)
4-26: LGTM! Well-documented implementation.The
next_permutationfunction is correctly implemented with clear step-by-step comments that explain the algorithm. The three-phase approach (find pivot, swap with successor, reverse suffix) is standard and efficient.
29-37: LGTM! Clean helper function.The
reversehelper function is well-implemented and correctly reverses the array segment from the start index to the end.algorithms/two_pointers/next_permutation/README.md (1)
44-97: LGTM! Excellent documentation.The explanation is comprehensive and well-structured. The step-by-step breakdown clearly explains the algorithm logic, including edge cases and the two-pointer approach. The time and space complexity analysis is accurate.
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Describe your change:
Next permutation of arrays
Checklist:
Fixes: #{$ISSUE_NO}.Summary by CodeRabbit
New Features
Documentation
Chores
✏️ Tip: You can customize this high-level summary in your review settings.