Suppose we have a binary string str, we have to check whether all of the 1s in the string are equidistant or not. In other words, the distance between every two 1s is same. And the string contains at least two 1s.
So, if the input is like s = "100001000010000", then the output will be True as the 1s are at distance 4 from each other.
To solve this, we will follow these steps −
Let us see the following implementation to get better understanding −
def solve(s): index =  for i in range(len(s)): if s[i] == '1': index.append(i) t = len(index) for i in range(1, t): if (index[i] - index[i - 1]) != (index - index): return False return True s = "100001000010000" print(solve(s))