Skip to content

feat(algorithms stacks): reverse string character array#186

Merged
BrianLusina merged 3 commits intomainfrom
feat/algorithms-stacks-reverse-string
Mar 9, 2026
Merged

feat(algorithms stacks): reverse string character array#186
BrianLusina merged 3 commits intomainfrom
feat/algorithms-stacks-reverse-string

Conversation

@BrianLusina
Copy link
Owner

@BrianLusina BrianLusina commented Mar 9, 2026

Describe your change:

Reverse string character array in place

  • 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

  • Documentation

    • Added a comprehensive Reverse String guide with examples, constraints and complexity notes.
  • New Features

    • Implemented in-place Reverse String using a two‑pointer approach.
    • Added several Stack algorithm entries (Asteroid Collision, Bracket Validator, Decimal To Binary, Decode String, Nextgreater, Removing Stars, Reverse String).
  • Tests

    • Added unit tests covering character‑array reversal scenarios; removed an obsolete PyMath test.
  • Refactor

    • Moved seven Stack items from Puzzles to Algorithms and updated PyMath entries.

@BrianLusina BrianLusina self-assigned this Mar 9, 2026
@BrianLusina BrianLusina added Algorithm Algorithm Problem Strings Array Array data structure Two Pointers Two pointer algorithm In Place Manipulation Refactor labels Mar 9, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 9, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7d3a667b-270f-4458-9317-199f313221e3

📥 Commits

Reviewing files that changed from the base of the PR and between 8ae26e0 and 24d1711.

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

📝 Walkthrough

Walkthrough

This pull request moves seven Stack entries from Puzzles > Queue to Algorithms > Stack in DIRECTORY.md, adds two PyMath entries, removes a PyMath test, adds an algorithms implementation and docs for in-place string reversal (reverse_string_char_array), introduces unit tests for it, and removes the puzzle-version README and test for reverse_string.

Changes

Cohort / File(s) Summary
Directory Manifest
DIRECTORY.md
Added Algorithms > Stack entries: Asteroid Collision, Bracket Validator, Decimal To Binary, Decode String, Nextgreater, Removing Stars, Reverse String; removed the same seven entries from Puzzles > Queue; added PyMath entries Power Of I, Power Of Two; removed Test Power Of I from PyMath tests.
Algorithms — Reverse String
algorithms/stack/reverse_string/README.md, algorithms/stack/reverse_string/__init__.py, algorithms/stack/reverse_string/test_reverse_string.py
Added README describing two‑pointer in‑place reversal; implemented reverse_string_char_array(s: List[str]) -> None using two pointers (O(n) time, O(1) space); added parameterised unit tests covering reverse_string and reverse_string_char_array.
Puzzles — Reverse String (removed)
puzzles/stack/reverse_string/README.md, puzzles/stack/reverse_string/test_reverse_string.py
Removed puzzle README content and the unittest-based test file for reverse_string, consolidating implementation under algorithms/stack.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

enhancement, Documentation, Stack

Poem

🐰 Hopping through directories, I shuffle each string,

Two pointers hold paws as the reversal bells ring,
Puzzles to Algorithms, the paths intertwine,
PyMath gains power — a neat little sign!

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The description follows the template structure and all checklist items are marked as complete, though some claims appear inconsistent with the actual changes made. Verify whether the PR truly changes only one algorithm file, as the raw summary shows changes across DIRECTORY.md, multiple reverse_string files, and multiple stack-related entries being reorganised.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding a reverse string character array algorithm to the algorithms/stack directory.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/algorithms-stacks-reverse-string

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

🧹 Nitpick comments (1)
algorithms/stack/reverse_string/test_reverse_string.py (1)

7-12: Consider adding empty list test case for complete edge case coverage.

The implementation handles empty lists (if not s), but there's no test case verifying this behaviour. Adding a test for the empty list edge case would improve coverage.

💡 Suggested addition
 REVERSE_STRING_CHAR_ARRAY_TEST_CASES = [
     (["a", "e", "i", "o", "u"], ["u", "o", "i", "e", "a"]),
     (["A", "l", "e", "x"], ["x", "e", "l", "A"]),
     (["p", "y", "t", "h", "o", "n"], ["n", "o", "h", "t", "y", "p"]),
     (["x"], ["x"]),
+    ([], []),
 ]
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@algorithms/stack/reverse_string/test_reverse_string.py` around lines 7 - 12,
Add an empty-list test case to REVERSE_STRING_CHAR_ARRAY_TEST_CASES to cover the
edge case where the input is [] and should remain [], e.g. append the tuple ([],
[]) to the list so the test suite verifies the implementation's early-return
branch (the code path using "if not s"); update the test data in
algorithms/stack/reverse_string/test_reverse_string.py by adding this tuple to
the existing REVERSE_STRING_CHAR_ARRAY_TEST_CASES.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@algorithms/stack/reverse_string/__init__.py`:
- Around line 36-48: Add a return type hint and a docstring to
reverse_string_char_array: change its signature to include "-> None" and add a
docstring immediately below the def that describes purpose, parameters, in-place
behavior, time O(n) and space O(1) complexity, and include a URL reference to an
explanatory resource (matching the style of reverse_string). Keep wording
consistent with the existing reverse_string docstring and mention that the
function mutates the input list in place.

In `@algorithms/stack/reverse_string/README.md`:
- Around line 45-46: Fix the missing space in the README sentence by changing
"size.Thus" to "size. Thus" in the space complexity paragraph (look for the
sentence containing "The solution’s space complexity is O(1), as the reversal is
done in place using only two pointers (left and right). No additional data
structures are required, regardless of the input size.Thus, the overall space
complexity remains O(1)."). Ensure there is a single space after the period
before "Thus".
- Around line 39-41: The time complexity paragraph contains a typographical
error: replace the stray "nnn" with "n" in the time complexity section
describing the input array s so the sentence reads "where n is the length of the
input array, s."; update the sentence that currently starts with "The solution’s
time complexity is O(n), where nnn is the length of the input array, s." to use
the single-letter n.

---

Nitpick comments:
In `@algorithms/stack/reverse_string/test_reverse_string.py`:
- Around line 7-12: Add an empty-list test case to
REVERSE_STRING_CHAR_ARRAY_TEST_CASES to cover the edge case where the input is
[] and should remain [], e.g. append the tuple ([], []) to the list so the test
suite verifies the implementation's early-return branch (the code path using "if
not s"); update the test data in
algorithms/stack/reverse_string/test_reverse_string.py by adding this tuple to
the existing REVERSE_STRING_CHAR_ARRAY_TEST_CASES.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1df2df47-3a81-4b4e-b774-d46e41521751

📥 Commits

Reviewing files that changed from the base of the PR and between 47d5f34 and 8ae26e0.

⛔ Files ignored due to path filters (3)
  • algorithms/stack/reverse_string/images/examples/reverse_string_example_1.png is excluded by !**/*.png
  • algorithms/stack/reverse_string/images/examples/reverse_string_example_2.png is excluded by !**/*.png
  • algorithms/stack/reverse_string/images/examples/reverse_string_example_3.png is excluded by !**/*.png
📒 Files selected for processing (25)
  • DIRECTORY.md
  • algorithms/stack/asteroid_collision/README.md
  • algorithms/stack/asteroid_collision/__init__.py
  • algorithms/stack/asteroid_collision/test_asteroid_collision.py
  • algorithms/stack/bracket_validator/README.md
  • algorithms/stack/bracket_validator/__init__.py
  • algorithms/stack/bracket_validator/test_bracket_validator.py
  • algorithms/stack/decimal_to_binary/README.md
  • algorithms/stack/decimal_to_binary/__init__.py
  • algorithms/stack/decimal_to_binary/test_decimal_to_binary.py
  • algorithms/stack/decode_string/README.md
  • algorithms/stack/decode_string/__init__.py
  • algorithms/stack/decode_string/test_decode_string.py
  • algorithms/stack/nextgreater/README.md
  • algorithms/stack/nextgreater/__init__.py
  • algorithms/stack/nextgreater/test_next_greater.py
  • algorithms/stack/removing_stars/README.md
  • algorithms/stack/removing_stars/__init__.py
  • algorithms/stack/removing_stars/test_remove_starts.py
  • algorithms/stack/reverse_string/README.md
  • algorithms/stack/reverse_string/__init__.py
  • algorithms/stack/reverse_string/test_reverse_string.py
  • puzzles/stack/__init__.py
  • puzzles/stack/reverse_string/README.md
  • puzzles/stack/reverse_string/test_reverse_string.py
💤 Files with no reviewable changes (2)
  • puzzles/stack/reverse_string/test_reverse_string.py
  • puzzles/stack/reverse_string/README.md

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@BrianLusina BrianLusina merged commit 43afedd into main Mar 9, 2026
6 of 8 checks passed
@BrianLusina BrianLusina deleted the feat/algorithms-stacks-reverse-string branch March 9, 2026 06:36
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 In Place Manipulation Refactor Strings Two Pointers Two pointer algorithm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant