bits made of the characters 0 and 1. Cut it into consecutive pieces so that each piece is the binary form of some power of five (1, 5, 25, 125, …) and does not start with a zero.
Return the smallest possible number of pieces. If the string cannot be cut this way, return -1.bits="1100101" → -1
The zeros at positions 2 and 3 must belong to a piece that starts earlier. The only such piece that is a power of five is "11001" (25), but it leaves "01", which starts with a zero. So the answer is −1.
bits="1111101" → 1
"1111101" is 125 = 5³, so a single piece is enough.
bits="10111" → 3
bits is 0 or 1bits="1100101"
-1
Run checks the first 3 tests in your browser. Submit checks all 98 tests on the server, hidden ones included.