Generate the First Rows of Pascal Coefficients

Quick Overview

Generate the first requested rows of Pascal’s triangle with exact adjacent-entry sums and bounded integer arithmetic.

Generate the First Rows of Pascal Coefficients

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

### Problem Return the first `numRows` rows of Pascal's triangle. The first row is `[1]`. Each later row starts and ends with 1, and every interior entry is the sum of the two entries immediately above it. Return rows from top to bottom, with entries in left-to-right order. ```cpp vector<vector<int>> generate(int numRows); ``` ### Examples ```text Input: numRows = 4 Output: [[1],[1,1],[1,2,1],[1,3,3,1]] ``` ```text Input: numRows = 2 Output: [[1],[1,1]] ``` ### Constraints - `1 <= numRows <= 30`.

Overview: Generate the first requested rows of Pascal’s triangle with exact adjacent-entry sums and bounded integer arithmetic.

Google logo
Google
Date not reported
easySoftware EngineerOtherCoding & Algorithms
0
0

Problem

Return the first numRows rows of Pascal's triangle. The first row is [1]. Each later row starts and ends with 1, and every interior entry is the sum of the two entries immediately above it. Return rows from top to bottom, with entries in left-to-right order.

vector<vector<int>> generate(int numRows);

Examples

Input: numRows = 4
Output: [[1],[1,1],[1,2,1],[1,3,3,1]]
Input: numRows = 2
Output: [[1],[1,1]]

Constraints

  • 1 <= numRows <= 30 .