I have trouble to successfully finish this task: 6035. Number of Ways to Select Buildings
I fail at input: "011001010"
My output is: 27
The expected output should be: 29
Thus, somehow I am missing 2 relevant combinations.
Anyone could help me to understand where is the mistake? Thanks!
class Solution:
def numberOfWays(self, s: str) -> int:
combos = []
o_inds = [e for e,i in enumerate(s) if i == '0']
l_inds = [e for e,i in enumerate(s) if i == '1']
while len(s)>=3 and '0' in s and '1' in s:
if s[0] == '0':
for i in o_inds:
o_ls = o_inds[1:]
for j in l_inds:
for k in o_ls[1:]:
if i<j<k:
combos.append((i,j,k))
else:
for i in l_inds:
l_ls = l_inds[1:]
for j in o_inds:
for k in l_ls[1:]:
if i<j<k:
combos.append((i,j,k))
s = s[1:]
return len(set(combos))
```