---
id: 69b1028d6e265413d0198a29
title: "Challenge 230: Pascal's Triangle Row"
challengeType: 29
dashedName: challenge-230
---

# --description--

Given an integer `n`, return the `n`th row of Pascal's triangle as an array.

In Pascal's Triangle, each row begins and ends with 1, and each interior value is the sum of the two values directly above it.

Here are the first 5 rows of the triangle:

```js
    1
   1 1
  1 2 1
 1 3 3 1
1 4 6 4 1
```

# --hints--

`pascal_row(5)` should return `[1, 4, 6, 4, 1]`.

```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(pascal_row(5), [1, 4, 6, 4, 1])`)
}})
```

`pascal_row(3)` should return `[1, 2, 1]`.

```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(pascal_row(3), [1, 2, 1])`)
}})
```

`pascal_row(1)` should return `[1]`.

```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(pascal_row(1), [1])`)
}})
```

`pascal_row(10)` should return `[1, 9, 36, 84, 126, 126, 84, 36, 9, 1]`.

```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(pascal_row(10), [1, 9, 36, 84, 126, 126, 84, 36, 9, 1])`)
}})
```

`pascal_row(15)` should return `[1, 14, 91, 364, 1001, 2002, 3003, 3432, 3003, 2002, 1001, 364, 91, 14, 1]`.

```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(pascal_row(15), [1, 14, 91, 364, 1001, 2002, 3003, 3432, 3003, 2002, 1001, 364, 91, 14, 1])`)
}})
```

# --seed--

## --seed-contents--

```py
def pascal_row(n):

    return n
```

# --solutions--

```py
def pascal_row(n):
    if n == 1:
        return [1]

    row = [1]

    for _ in range(2, n + 1):
        next_row = [1]

        for i in range(1, len(row)):
            next_row.append(row[i - 1] + row[i])

        next_row.append(1)
        row = next_row

    return row
```
