Smallest string period

Write codeMedium25 minGoogle style

Your task

The smallest period of a string s is the length of the shortest prefix p such that s is formed by repeating p a whole number of times (so "abcabcabc" has smallest period 3, "aaaa" has 1, and "abcd" has 4 because it does not repeat). Return that period length for the given s; for the empty string return 0. The string can be up to 10^5 characters, so brute-forcing every candidate period and verifying it character-by-character may be too slow.

Examples

smallest_period(s: str) -> int
Example 1
Inputsmallest_period("abcabcabc")
Output3