Skip to content

feat: add optimized Digit DP template and unit tests#7430

Open
premmsharma122 wants to merge 5 commits into
TheAlgorithms:masterfrom
premmsharma122:feature/digit-dp-algorithm
Open

feat: add optimized Digit DP template and unit tests#7430
premmsharma122 wants to merge 5 commits into
TheAlgorithms:masterfrom
premmsharma122:feature/digit-dp-algorithm

Conversation

@premmsharma122
Copy link
Copy Markdown

Types of Changes

  • New algorithm implementation

Description

This PR introduces a clean and optimized template implementation for the Digit Dynamic Programming (Digit DP) technique under the dynamicprogramming package.

Key enhancements integrated into this template include:

  1. Magic Numbers Elimination:
    Replaced hardcoded dimensions with a clear MAX_DIGIT_SUM constant representing the maximum theoretical digit sum for a 64-bit signed long integer.

  2. Explicit Complexity Documentation:
    Added dedicated JavaDoc comments documenting the state-space complexity:

    • Time Complexity: O(number_of_digits × target_sum × 10)
    • Space Complexity: O(number_of_digits × target_sum × 2)
  3. Educational Enhancements:
    Included detailed inline documentation, state-transition explanations, pruning optimization comments, and practical JavaDoc examples for easier understanding of Digit DP concepts.

  4. Comprehensive Test Coverage:
    Added multiple JUnit test cases covering:

    • standard ranges,
    • zero-bound handling,
    • invalid ranges,
    • impossible target sums,
    • and edge-case validations.

Related Issue

Closes #7429

Checklist

  • My code follows the code style of this project (mvn checkstyle:check passed locally).
  • I have performed a self-review of my own code.
  • I have added comprehensive test coverage that passes successfully (mvn test passed locally).

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 19, 2026

Codecov Report

❌ Patch coverage is 96.42857% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 79.65%. Comparing base (4b8099c) to head (abc31a4).

Files with missing lines Patch % Lines
.../com/thealgorithms/dynamicprogramming/DigitDP.java 96.42% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #7430      +/-   ##
============================================
+ Coverage     79.63%   79.65%   +0.01%     
- Complexity     7241     7254      +13     
============================================
  Files           800      801       +1     
  Lines         23608    23636      +28     
  Branches       4646     4654       +8     
============================================
+ Hits          18800    18827      +27     
+ Misses         4055     4054       -1     
- Partials        753      755       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

[FEATURE REQUEST] Add Digit Dynamic Programming Template

2 participants