233. A Row of Pascal’s Triangle
Core1000 ms256 MBSolved by 0%
Print row n of Pascal's triangle, counting rows from 0. Row 0 is a single
1.
row 0: 1
row 1: 1 1
row 2: 1 2 1
row 4: 1 4 6 4 1
Each entry is the sum of the two above it, with the ends always 1. Written as plain recursion that recomputes the same entries exponentially often, exactly like Fibonacci.
You only need one row at a time, so the whole thing can be built from the previous row with no table at all.
Constraints - `0 ≤ n ≤ 30`
Input
A single line containing one integer n.
Output
Print the n + 1 values of row n, separated by single spaces.
Input4
Output1 4 6 4 1
Noteis a row small enough to check by hand
Input0
Output1
Noteis row zero, a single 1
Hint 1Approach
Hint 2Approach
Hint 3Pseudocode
Hint 4Full solution