-
-
Notifications
You must be signed in to change notification settings - Fork 630
Add solution for Challenge 23 by nzamulov #564
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Pre-merge checks❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🔇 Additional comments (5)
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. Comment |
There was a problem hiding this 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
🧹 Nitpick comments (1)
challenge-23/submissions/nzamulov/solution-template.go (1)
84-85
: Consider scoping constants locally or using more descriptive names.The global constants
p
andmod
could be moved insideRabinKarpSearch
or given more descriptive names likerabinKarpBase
andrabinKarpMod
to clarify their purpose and scope.Example refactor:
-const p int64 = 31 -const mod = int64(1e7 + 7) - // RabinKarpSearch implements the Rabin-Karp algorithm to find pattern in text. // Returns a slice of all starting indices where the pattern is found. func RabinKarpSearch(text, pattern string) []int { + const base int64 = 31 + const mod int64 = 1e7 + 7
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
challenge-23/submissions/nzamulov/solution-template.go
(1 hunks)
🔇 Additional comments (3)
challenge-23/submissions/nzamulov/solution-template.go (3)
7-39
: LGTM!The main function correctly sets up test cases and exercises all three pattern matching algorithms. The test cases cover various scenarios including overlapping patterns and repeated characters.
56-82
: LGTM! KMP implementation is correct.The Knuth-Morris-Pratt algorithm is correctly implemented using the pattern+separator+text concatenation approach. The prefix function (pi array) is built correctly, and the index calculation at line 78 (
i - 2 * len(pattern)
) accurately maps match positions from the concatenated string back to the original text.
87-122
: LGTM! Rabin-Karp implementation is correct.The Rabin-Karp algorithm is correctly implemented with:
- Proper rolling hash using position-weighted powers
- Correct hash comparison accounting for window offset (
curr_ht == hp * pows[i]
)- String verification to avoid false positives from hash collisions
- Appropriate handling of negative values in modulo arithmetic (line 116)
- Edge case validation (empty pattern, pattern longer than text)
The algorithm is sound and handles all edge cases properly.
Challenge 23 Solution
Submitted by: @nzamulov
Challenge: Challenge 23
Description
This PR contains my solution for Challenge 23.
Changes
challenge-23/submissions/nzamulov/solution-template.go
Testing
Thank you for reviewing my submission! 🚀