3540. Hash Divided String
My accepted Python solution to LeetCode problem 3540, Hash Divided String, running in 19ms.
- Difficulty: Medium
- Python
- Runtime 19ms
- Memory 17.2MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 19ms, memory 17.2MB, accepted 2025-12-29.
class Solution:
def stringHash(self, s: str, k: int) -> str:
result = []
n = len(s)
for i in range(0, n, k):
substring = s[i:i+k]
hash_sum = sum(ord(c) - ord('a') for c in substring)
hashed_char = chr(ord('a') + hash_sum % 26)
result.append(hashed_char)
return ''.join(result)