← Back to challenges

Greater Than the Sum?

PythonHardarrayslanguage_fundamentals

Instructions

For each number in a list, check if that number is greater than the sum of all numbers that appear before it in the list. If all numbers in the list pass this test, return True. Return False otherwise.

Examples

greater_than_sum([2, 3, 7, 13, 28]) ➞ True

# 3 > 2 = True
# 7 > 2 + 3 = True
# 13 > 2 + 3 + 7 = True
# 28 > 2 + 3 + 7 + 13 = True

greater_than_sum([1, 2, 4, 6, 13]) ➞ False

# 2 > 1 = True
# 4 > 1 + 2 = True
# 6 > 1 + 2 + 4 = False
# 13 > 1 + 2 + 4 + 6 = False

Notes

The first number in any list will always pass the test.

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Solve a Linear Equation