FastPrepFastPrep
Problem Brief

Pascal's Triangle

FULLTIMEONSITE INTERVIEW

Complete the function below. The function receives the number of rows and returns the generated Pascal's Triangle.

Problem

Problem: Pascal's Triangle

Given a non-negative integer numRows, generate the first numRows rows of Pascal's Triangle and return them as a 2D array triangle.

Pascal's Triangle is defined as:

Row i (0-indexed) contains i+1 elements.

The first and last element of each row is 1.

For other positions: triangle[i][j] = triangle[i-1][j-1] + triangle[i-1][j] for 0 < j < i.

Input

A single integer: numRows

Output

Print a 2D array (you may print each row as a list) representing the first numRows rows.

Constraints

0 <= numRows <= 30

Example

Input:

5

Output:

[

[1],

[1,1],

[1,2,1],

[1,3,3,1],

[1,4,6,4,1]

]

Example

Input

0

Output

[]

Function Description

Complete solvePascalsTriangle. It has one parameter, int numRows. Return the first numRows rows of Pascal's Triangle as a 2D integer array.

1Example 1

Input
numRows = 5
Output
[[1], [1, 1], [1, 2, 1], [1, 3, 3, 1], [1, 4, 6, 4, 1]]
Explanation

The returned string array must match the expected standard output lines for the sample input.

Constraints

Limits and guarantees your solution can rely on.

Use the limits and requirements stated in the prompt.

public int[][] solvePascalsTriangle(int numRows) {
    // write your code here
}
Input

numRows

5

Output

[[1], [1, 1], [1, 2, 1], [1, 3, 3, 1], [1, 4, 6, 4, 1]]

Sign in to submit your solution.