A landscaper is building a terraced garden with numRows terraces, stacked from top to bottom. The topmost terrace holds a single plot with exactly one plant. Every terrace after the first has one more plot than the terrace above it: the two edge plots of each terrace always hold exactly one plant each, and every interior plot's plant count equals the sum of the plant counts of the two plots directly above it (the one above-left and the one above-right) on the previous terrace. Given the number of terraces to build, output the plant count of every plot, terrace by terrace from top to bottom.
A single integer numRows on the only line of input.
numRows lines. The i-th line (1-indexed from the top) contains i space-separated integers — the plant counts of that terrace's plots, left to right.
1 <= numRows <= 30Example 1
Input
1
Expected
1
Explanation
With a single terrace there is exactly one plot, and every terrace's edge plots always hold exactly 1 plant, so the only output line is '1'.
Example 2
Input
5
Expected
1 1 1 1 2 1 1 3 3 1 1 4 6 4 1
Explanation
Terrace 1 is [1]. Terrace 2's two plots are both edges, so it's [1, 1]. Terrace 3 has edges 1 and 1, and its one interior plot sums the two plots above it (1+1=2), giving [1, 2, 1]. Terrace 4's interior plots are 1+2=3 and 2+1=3, giving [1, 3, 3, 1]. Terrace 5's interior plots are 1+3=4, 3+3=6, and 3+1=4, giving [1, 4, 6, 4, 1].
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →