Last active
April 29, 2022 16:56
-
-
Save PMExtra/a2dc4b9ab672250201341f077d2053b5 to your computer and use it in GitHub Desktop.
[Google Foobar] https://foobar.withgoogle.com/
This file contains 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
def solution(s): | |
if not s: return 0 | |
result = 1 | |
min_divisor = 2 | |
while True: | |
length = len(s) | |
factor = 1 | |
# loop in a preprocessed prime number list can improve performance | |
for n in range(min_divisor, length + 1): | |
if length % n: continue | |
chunk_size = length // n | |
chunks = [s[i:i + chunk_size] for i in range(0, length, chunk_size)] | |
if chunks.count(chunks[0]) != len(chunks): continue | |
s = chunks[0] | |
min_divisor = n | |
factor = n | |
break | |
if factor == 1: break | |
result *= factor | |
return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment