Skip to content

Conversation

@shreeya-g10
Copy link
Contributor

What does this PR do?

This pull request adds a new backtracking algorithm to generate UNIQUE permutations
of a given string, even when duplicate characters exist.

Features of this contribution:

  • Handles duplicate characters using sorted array + duplicate-skip logic
  • Uses backtracking with boolean usage tracking
  • Generates permutations in lexicographical order
  • Time complexity: O(n! * n)

Test Cases Added

Added JUnit test file UniquePermutationTest.java with:

  • AAB → ["AAB", "ABA", "BAA"]
  • ABC → 6 permutations
  • Empty string → [""]
    These ensure correctness and edge case handling.

Folder Structure

  • src/main/java/com/thealgorithms/backtracking/UniquePermutation.java
  • src/test/java/com/thealgorithms/backtracking/UniquePermutationTest.java

Why this is useful

This algorithm is a fundamental backtracking pattern and
is not currently present in the repository in unique form.
It adds educational value and ensures correctness through test cases.

Validation

  • Code compiles successfully
  • All tests pass locally using JUnit
  • [ x] I have read CONTRIBUTING.md.
  • [ x] This pull request is all my own work -- I have not plagiarized it.
  • [ x] All filenames are in PascalCase.
  • [ x] All functions and variable names follow Java naming conventions.
  • All new algorithms have a URL in their comments that points to Wikipedia or other similar explanations.
  • All new code is formatted with clang-format -i --style=file path/to/your/file.java

@codecov-commenter
Copy link

codecov-commenter commented Nov 18, 2025

Codecov Report

❌ Patch coverage is 81.81818% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.45%. Comparing base (1c97ad8) to head (016a76f).

Files with missing lines Patch % Lines
.../thealgorithms/backtracking/UniquePermutation.java 81.81% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #7078      +/-   ##
============================================
- Coverage     78.46%   78.45%   -0.01%     
- Complexity     6738     6745       +7     
============================================
  Files           757      758       +1     
  Lines         22317    22339      +22     
  Branches       4380     4384       +4     
============================================
+ Hits          17510    17527      +17     
- Misses         4104     4107       +3     
- Partials        703      705       +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.

@shreeya-g10 shreeya-g10 force-pushed the add-unique-permutation branch from 8c80879 to 8b89e9d Compare November 18, 2025 21:53
Copy link
Member

@alxkm alxkm left a comment

Choose a reason for hiding this comment

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

Thank you for the contribution.

@alxkm alxkm merged commit 3519e39 into TheAlgorithms:master Nov 19, 2025
6 checks passed
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.

3 participants