My solutions for google foobar
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

34 lines
850 B

"""
Almost no computation there, we get positions of arrows depending of their type
sorted and then do two nested loops to detect collisions, can't think of
anything better rn
"""
def answer(s):
# readme.txt
if(len(s) > 100 or len(s) < 1):
raise ValueError('Height is outside of bounds')
# we keep only the arrows and cast it into a list ot make it iterable easily
s = list(s.replace("-",""))
left = []
right = []
res=0
for i in range(0,len(s)):
if s[i] == '<':
left.append(i)
if s[i] == '>':
right.append(i)
# two nested loops to detect collision
for i in right:
for y in left:
if i < y:
res+=1
for i in left:
for y in right:
if y < i:
res+=1
return res