Skip to content

Comments

Improve minimum-deletions-to-make-string-balanced space complexity to O(1)#20

Merged
yamcodes merged 18 commits intomainfrom
18-improve-minimum-deletions-space-complexity-to-o1
Feb 14, 2026
Merged

Improve minimum-deletions-to-make-string-balanced space complexity to O(1)#20
yamcodes merged 18 commits intomainfrom
18-improve-minimum-deletions-space-complexity-to-o1

Conversation

@yamcodes
Copy link
Owner

@yamcodes yamcodes commented Feb 10, 2026

Closes #18

Summary by CodeRabbit

  • Documentation
    • Expanded docs and README to describe multiple solution variants, progression notes, and updated metadata.
  • New Features
    • Added several alternative solution variants (naive, DP scaffold, memoized, prefix/suffix, recursive) as distinct approaches.
  • Performance
    • Optimized the primary solution to a single-pass constant-space implementation.
  • Tests
    • Introduced shared test data and dedicated parameterized test classes for each solution; some scaffolded tests are currently disabled.

@yamcodes yamcodes linked an issue Feb 10, 2026 that may be closed by this pull request
@coderabbitai
Copy link

coderabbitai bot commented Feb 10, 2026

Caution

Review failed

The pull request is closed.

Walkthrough

Refactors the primary solution to a single-pass O(1) space implementation, adds multiple solution variants (naive, prefix/suffix, recursive, memoized, DP scaffold), centralizes test data in TestCases.java, introduces per-variant parameterized tests (many disabled/placeholders), and updates documentation and IDE run configuration.

Changes

Cohort / File(s) Summary
Core Solution
src/main/java/codes/yam/leetcode/minimumdeletionstomakestringbalanced/Solution.java
Replaced previous split-based approach with a single-pass O(1) space implementation; removed getSliceInfo and minimumDeletionsNaive.
Additional Solution Variants
src/main/java/codes/yam/leetcode/minimumdeletionstomakestringbalanced/SolutionNaive.java, .../SolutionPrefixSuffix.java, .../SolutionRecursive.java, .../SolutionMemoized.java, .../SolutionDp.java
Added multiple variant implementations: naive (O(n²)), prefix/suffix (O(n) time, O(n) space), recursive/memoized stubs (unimplemented), and a DP scaffold (throws UnsupportedOperationException).
Tests: centralization & per-variant
src/test/java/codes/yam/leetcode/minimumdeletionstomakestringbalanced/TestCases.java, SolutionTest.java, SolutionNaiveTest.java, SolutionPrefixSuffixTest.java, SolutionRecursiveTest.java, SolutionMemoizedTest.java, SolutionDpTest.java
Introduced TestCases provider used via @MethodSource and added parameterized test classes for each solution variant; several tests are annotated @Disabled and some reference unimplemented variants. SolutionTest made package-private and simplified to use centralized cases.
Docs & Metadata
README.md, CLAUDE.md, src/main/java/.../package-info.java
Expanded documentation to describe multi-solution layout, prefix-based naming, progression notes, and updated complexity claims (Solution now O(1) space).
IDE Config
.idea/runConfigurations/Test_All.xml
Renamed JUnit run configuration from "Test" to "Test All".

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 Hopping through code with a carrot of glee,
I trimmed needless arrays to keep things O(1) — whee!
Naive, DP, and prefixes lined up in a row,
Tests gathered together so each method can show.
Tiny paws, big refactor — onward I go! 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The PR includes extensive out-of-scope changes: documentation updates (CLAUDE.md, README.md, package-info.java), IDE config changes (.idea/runConfigurations/Test_All.xml), test infrastructure (TestCases.java shared data), and multiple alternative solution scaffolds (SolutionNaive, SolutionDp, SolutionMemoized, SolutionRecursive, SolutionPrefixSuffix) not mentioned in issue #18. Consider separating the O(1) space optimization for Solution.java from documentation updates and alternative solution scaffolds into focused pull requests with specific issues.
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.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main objective: improving space complexity from O(n) to O(1) for the minimum-deletions solution, which is clearly reflected in the Solution.java changes.
Linked Issues check ✅ Passed The PR successfully implements the primary requirement from issue #18: the Solution.java file now uses an O(1) space, single-pass DP approach tracking counters instead of prefix/suffix arrays.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into main

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 18-improve-minimum-deletions-space-complexity-to-o1

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.

@yamcodes yamcodes changed the title Add IntelliJ IDEA run configurations to gitignore and JUnit launcher … Improve minimum-deletions space complexity to O(1) Feb 10, 2026
@yamcodes yamcodes changed the title Improve minimum-deletions space complexity to O(1) Improve minimum-deletions-to-make-string-balanced space complexity to O(1) Feb 10, 2026
@yamcodes yamcodes marked this pull request as ready for review February 14, 2026 16:35
Copy link

@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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
README.md (1)

13-13: ⚠️ Potential issue | 🟡 Minor

Update README.md to reflect O(1) space complexity for problem 1653.

The Solution.java now correctly uses O(1) space (as shown in its Javadoc), but the solutions table still shows the stale O(n) value. Update line 13 in README.md to match.

Proposed fix
-| 1653 | [Minimum Deletions to Make String Balanced](https://leetcode.com/problems/minimum-deletions-to-make-string-balanced/) | Medium     | `O(n)`            | `O(n)` |
+| 1653 | [Minimum Deletions to Make String Balanced](https://leetcode.com/problems/minimum-deletions-to-make-string-balanced/) | Medium     | `O(n)`            | `O(1)` |
🤖 Fix all issues with AI agents
In
`@src/main/java/codes/yam/leetcode/minimumdeletionstomakestringbalanced/Solution.java`:
- Line 6: Update the Javadoc in Solution.java to stop claiming it "Optimizes
{`@code` SolutionDp}" since SolutionDp is unimplemented; edit the summary to
accurately describe the implemented algorithm (e.g., "Uses a
split-point/counting approach to compute minimum deletions in constant space")
or remove the DP reference, and ensure the Javadoc mentions the current approach
by name so readers are not misled by the unimplemented class {`@code` SolutionDp}
or the TODO in package-info.java.
🧹 Nitpick comments (4)
src/main/java/codes/yam/leetcode/minimumdeletionstomakestringbalanced/package-info.java (1)

26-31: Documentation contradicts itself about Solution's approach.

Line 26 lists Solution as "Space-optimized DP, O(n) time, O(1) space" in the DP progression, but lines 29–31 state it currently uses a split-point approach and should later be replaced with the DP formulation. This is confusing for readers — Solution appears in the DP progression list despite not being DP yet.

Consider either removing Solution from the DP progression until it actually uses DP, or clarifying the current listing (e.g., placeholder entry marked as "planned").

src/test/java/codes/yam/leetcode/minimumdeletionstomakestringbalanced/TestCases.java (1)

11-19: Consider adding edge cases for empty string and already-balanced inputs.

The test suite covers a good variety of patterns but misses a few boundary cases: "" (empty → 0), "a" (single char → 0), and "ab" (already balanced → 0). These help catch off-by-one or empty-input issues.

CLAUDE.md (1)

28-34: Add a language specifier to the fenced code block.

Static analysis (markdownlint MD040) flags this code block as missing a language identifier. Adding text or leaving it consistent with the other directory-tree block above would resolve the warning.

Proposed fix
-```
+```text
 src/test/java/codes/yam/leetcode/{problemslug}/
 ├── TestCases.java          # Shared test data (static Stream<Arguments> cases())
 ├── SolutionTest.java       # Tests Solution.java
 ├── SolutionNaiveTest.java  # Tests SolutionNaive.java (one test file per solution)
 └── SolutionDpTest.java
-```
+```
src/main/java/codes/yam/leetcode/minimumdeletionstomakestringbalanced/Solution.java (1)

20-35: The algorithm is correct but non-obvious — consider adding a brief explanatory comment.

The split-point tracking logic with aAfter, bBefore, and the reset condition is clever but not immediately intuitive. A short comment explaining the invariant (e.g., "track the cost of the best split point seen so far; reset when deleting all b's becomes cheaper") would help future readers.

@yamcodes yamcodes merged commit 4d754eb into main Feb 14, 2026
1 check passed
@yamcodes yamcodes deleted the 18-improve-minimum-deletions-space-complexity-to-o1 branch February 14, 2026 16:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve minimum-deletions space complexity to O(1)

1 participant