fork download
  1. def calculate(walls):
  2. prev = 0
  3. max = 0
  4. localSum = 0
  5. totalSum = 0
  6.  
  7. for i in xrange(len(walls)):
  8. if i < prev and max == 0:
  9. max = prev
  10.  
  11. if walls[i] >= max:
  12. max = 0
  13. totalSum += localSum
  14. localSum = 0
  15.  
  16. if not max == 0:
  17. localSum += max - walls[i]
  18.  
  19. prev = walls[i]
  20. return totalSum
  21.  
  22. print calculate([0, 5, 0, 1, 0, 2, 1, 0])
Success #stdin #stdout 0.01s 7852KB
stdin
Standard input is empty
stdout
0