Krakob

Dovy's problem

May 30th, 2014
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. An array has a special property which is the following:
  2. Every number which is ahead of another is bigger than the sum of the previous ones.
  3. Could you write a function to verify if this specific array exhibits this property?
  4.  
  5. Example array:
  6. 1, 2, 4, 8, 30
  7.  
  8. Solution, pseudocode:
  9. function verify(array):
  10. sum = 0
  11. for(i = 0; i < array.length; i++):
  12. if sum > array[i]:
  13. return false
  14. sum += array[i]
  15. return true
  16.  
  17. Solution, python:
  18. def verify(array):
  19. sum = 0
  20. for i in array:
  21. if sum > i:
  22. return false
  23. sum += i
  24. return true
Advertisement
Add Comment
Please, Sign In to add comment