fix(strings): use frequency-based signature for anagrams#12926
Closed
sowndappan5 wants to merge 13 commits intoTheAlgorithms:masterfrom
sowndappan5:master
Closed
fix(strings): use frequency-based signature for anagrams#12926sowndappan5 wants to merge 13 commits intoTheAlgorithms:masterfrom sowndappan5:master
sowndappan5 wants to merge 13 commits intoTheAlgorithms:masterfrom
sowndappan5:master
Conversation
docstrings, and ensured compliance with guidelines.
hinting, docstrings, and readability. Refactored variable names, optimized node handling, and ensured consistency in return types. Updated doctests for accuracy.
deletion, and improved readability.
for more information, see https://pre-commit.ci
streamline interactive and benchmarking sections.
for more information, see https://pre-commit.ci
Replaced the sorting-based signature implementation with a frequency-based approach using `collections.Counter`. This ensures that the signature represents both characters and their counts, preventing collisions and better grouping of true anagrams. Examples: - "test" → "e1s1t2" - "finaltest" → "a1e1f1i1l1n1s1t2" - "this is a test" → " 3a1e1h1i2s3t3" Also updated the anagram lookup to use the new frequency-based signatures, making results more accurate and avoiding false positives.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaced the sorting-based signature implementation with a frequency-based
approach using
collections.Counter.Changes
signature()to produce frequency-based keysTests
Breaking Changes
signature()output format changed from sorted-letters to frequency-basedDescribe your change:
Checklist: