Open
Conversation
haroldks
requested changes
Nov 27, 2025
Collaborator
haroldks
left a comment
There was a problem hiding this comment.
Hello Alexis,
Thank you for your exercise. It is a very interesting one. In general, there is too much to do for the students in my opinion. The challenge here should only focus on think about rolling hash to compute the hash of the word rotations.
I would suggest :
- Giving the student a method or function to compute the hash of the base word
- In you solution extract the rotation par in a method with relevant comments so when looking at the solution we know what is happening
- maybe use digit instead of char as input for the solve method to simplify test writings
- Add a comment for the base exponent precomputation
I also think that it can be possible to track the best while avoiding using pair and comparable in the end. I've add an idea in the comments but we can discuss it further.
Contributor
Author
|
Hey @haroldks, I've taken account the proposed modifications for the exercise, I've moved the hashing logic into a separate function and removed the minimum pair things. Now only a valid pair is required. |
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.
Hello,
Here is a new exercise about polynomial hash.
The solution idea is to compute the hash for each row with polynomial hash for e.g the string "hello" we have
hash = (h · a⁰ + e · a¹ + l · a² + l · a³ + o · a⁴) mod m (where a is the base and m the modulo)
and then we can rotate the string by simply doing some math operation on the already hashed string so to get "ohell" we remove the o from "hello"
hash = (h · a⁰ + e · a¹ + l · a² + l · a³ ) mod m
Then we multiply the hash by the basis (a)
hash = (h · a⁰ + e · a¹ + l · a² + l · a³ ) · a = (h · a¹ + e · a² + l · a³ + l · a⁴ ) mod m
And finally we add the o at the start:
(h · a¹ + e · a² + l · a³ + l · a⁴ ) + o · a⁰ = ( o· a⁰ + h · a¹ + e · a² + l · a³ + l · a⁴ ) mod m
And now we have the hash for "ohell" in O(1).