> ## Documentation Index
> Fetch the complete documentation index at: https://leetcode-py.wisl.dev/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> leetcode-py is a Python LeetCode practice environment generator with one CLI: lcpy. It is not a service or platform.
> Each problem is a directory under leetcode/ with README.md, solution.py, test_solution.py, helpers.py, and playground.ipynb. lcpy gen creates them from JSON templates bundled with the package.
> Examples are backed by tests; copy them verbatim.

# Pascal's Triangle II Python Solution

> Tested Python solution for LeetCode 119 with 16 pytest cases. Generate a practice environment with lcpy.

LeetCode 119, [Easy](/catalog/easy). Topics: [Array](/catalog/topics/array), [Dynamic Programming](/catalog/topics/dynamic-programming). [View on LeetCode](https://leetcode.com/problems/pascals-triangle-ii/description/).

Generate this problem as a practice environment: tested reference solution, 16 [parametrized pytest cases](/practice/testing), and a playground notebook:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
lcpy gen -n 119   # by problem number
lcpy gen -s pascals_triangle_ii   # by problem name
```

## Problem

Given an integer `rowIndex`, return the `rowIndexth` (**0-indexed**) row of the **Pascal's triangle**.

In **Pascal's triangle**, each number is the sum of the two numbers directly above it as shown:

![Pascal's Triangle](https://upload.wikimedia.org/wikipedia/commons/0/0d/PascalTriangleAnimated2.gif)

### Examples

```
Input: rowIndex = 3
Output: [1,3,3,1]
```

```
Input: rowIndex = 0
Output: [1]
```

```
Input: rowIndex = 1
Output: [1,1]
```

### Constraints

* 0 \<= rowIndex \<= 33

**Follow up:** Could you optimize your algorithm to use only `O(rowIndex)` extra space?

## Solution

Reference implementation from [solution.py on GitHub](https://github.com/wislertt/leetcode-py/blob/main/leetcode/pascals_triangle_ii/solution.py), full suite in [test\_solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/pascals_triangle_ii/test_solution.py):

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
class Solution:
    # Time: O(n^2)
    # Space: O(n)
    def get_row(self, row_index: int) -> list[int]:
        row = [1]
        for _ in range(row_index):
            row.append(1)
            for i in range(len(row) - 2, 0, -1):
                row[i] += row[i - 1]
        return row
```

## Complexity

| Time | Space |
| - | - |
| O(n^2) | O(n) |

## Tags

[NeetCode All](/catalog/neetcode).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.