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.

35 lines
850B

  1. """
  2. Almost no computation there, we get positions of arrows depending of their type
  3. sorted and then do two nested loops to detect collisions, can't think of
  4. anything better rn
  5. """
  6. def answer(s):
  7. # readme.txt
  8. if(len(s) > 100 or len(s) < 1):
  9. raise ValueError('Height is outside of bounds')
  10. # we keep only the arrows and cast it into a list ot make it iterable easily
  11. s = list(s.replace("-",""))
  12. left = []
  13. right = []
  14. res=0
  15. for i in range(0,len(s)):
  16. if s[i] == '<':
  17. left.append(i)
  18. if s[i] == '>':
  19. right.append(i)
  20. # two nested loops to detect collision
  21. for i in right:
  22. for y in left:
  23. if i < y:
  24. res+=1
  25. for i in left:
  26. for y in right:
  27. if y < i:
  28. res+=1
  29. return res