Can someone explain to me the space complexity of the following code?
def countBinarySubstrings(s):
groups = [1]
for i in range(1, len(s)):
if s[i-1] != s[i]:
groups.append(1)
else:
groups[-1] += 1
ans = 0
for i in range(1, len(groups)):
ans += min(groups[i-1], groups[i])
return ans
print(countBinarySubstrings('110010'))
Since I am creating a new list, I think the space complexity is O(n) but I am not sure.