You are given a string
s
of lengthn
and an integerk
, wheren
is a multiple ofk
. Your task is to hash the strings
into a new string calledresult
, which has a length ofn / k
.First, divide
s
inton / k
substrings, each with a length ofk
. Then, initializeresult
as an empty string.For each substring in order from the beginning:
- The hash value of a character is the index of that character in the English alphabet (e.g.,
'a' → 0
,'b' → 1
, …,'z' → 25
).- Calculate the sum of all the hash values of the characters in the substring.
- Find the remainder of this sum when divided by 26, which is called
hashedChar
.- Identify the character in the English lowercase alphabet that corresponds to
hashedChar
.- Append that character to the end of
result
.
1 |
|