Compute One Zero-Indexed Pascal Row

Quick Overview

Compute a zero-indexed Pascal row using descending in-place updates and only linear result storage.

Compute One Zero-Indexed Pascal Row

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

### Problem Return the row at zero-based index `rowIndex` in Pascal's triangle. Row 0 is `[1]`. Every row begins and ends with 1; each interior entry adds the two entries directly above it. ```cpp vector<int> getRow(int rowIndex); ``` ### Examples ```text Input: rowIndex = 4 Output: [1,4,6,4,1] ``` ```text Input: rowIndex = 2 Output: [1,2,1] ``` ### Constraints - `0 <= rowIndex <= 33`. ### Optional follow-up Can you compute the row using only `O(rowIndex)` extra space?

Overview: Compute a zero-indexed Pascal row using descending in-place updates and only linear result storage.

Amazon logo
Amazon
Source window: 0–3 months · as of Oct 21, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

Problem

Return the row at zero-based index rowIndex in Pascal's triangle. Row 0 is [1]. Every row begins and ends with 1; each interior entry adds the two entries directly above it.

vector<int> getRow(int rowIndex);

Examples

Input: rowIndex = 4
Output: [1,4,6,4,1]
Input: rowIndex = 2
Output: [1,2,1]

Constraints

  • 0 <= rowIndex <= 33 .

Optional follow-up

Can you compute the row using only O(rowIndex) extra space?