Partition String Into Minimum Beautiful Substrings

A string piece is "beautiful" when it is the binary representation of 5^j for an integer j >= 0, written with no leading zeros. The valid pieces are "1" (5^0), "101" (5^1), "11001" (5^2), and so on. The single character "0" is never beautiful, because no power of 5 equals 0. Partition the string into consecutive beautiful substrings using the fewest pieces and return that minimum count; return -1 when no valid partition exists.

Examples
Input: "1011"
Output: 2
Hints

Partition String Into Minimum Beautiful Substrings

A string piece is "beautiful" when it is the binary representation of 5^j for an integer j >= 0, written with no leading zeros. The valid pieces are "1" (5^0), "101" (5^1), "11001" (5^2), and so on. The single character "0" is never beautiful, because no power of 5 equals 0. Partition the string into consecutive beautiful substrings using the fewest pieces and return that minimum count; return -1 when no valid partition exists.