MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / longest_prefix

Function longest_prefix

strings/prefix_function.py:44–58  ·  view source on GitHub ↗

Prefix-function use case Finding longest prefix which is suffix as well >>> longest_prefix("aabcdaabc") 4 >>> longest_prefix("asdasdad") 4 >>> longest_prefix("abcab") 2

(input_str: str)

Source from the content-addressed store, hash-verified

42
43
44def longest_prefix(input_str: str) -> int:
45 """
46 Prefix-function use case
47 Finding longest prefix which is suffix as well
48
49 >>> longest_prefix("aabcdaabc")
50 4
51 >>> longest_prefix("asdasdad")
52 4
53 >>> longest_prefix("abcab")
54 2
55 """
56
57 # just returning maximum value of the array gives us answer
58 return max(prefix_function(input_str))
59
60
61if __name__ == "__main__":

Callers

nothing calls this directly

Calls 1

prefix_functionFunction · 0.85

Tested by

no test coverage detected