← Back to challenges

Simple Row Sum

PythonHardalgorithmslogicmathnumbersrecursion

Instructions

Imagine this triangle:

    1
   2 3
  4 5 6
 7 8 9 10
...

Create a function that takes a number n and returns the sum of all numbers in nth row.

Examples

row_sum(1) ➞ 1

row_sum(2) ➞ 5

row_sum(4) ➞ 34

Notes

1 <= N <= 1000

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.