Z-algorithm sum
Given a string s, return the SUM over all indices i of the length of the longest common prefix between s and the suffix of s starting at i (for i=0 this is len(s) itself). 1 <= len(s) <= 100000, lowercase letters. Example: 'ababa' -> z = [5,0,3,0,1], sum = 9.
Implement
sum_z_values(s: str) → intExamples
in
["ababa"]out9What a strong answer looks like
State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
0:00 of about 25 min
solution.py
InputExpectedGot
["ababa"]9not run yetsample