Back to questions

Pascals Triangle (Part 2) Uber Python Interview Question

Pascals Triangle (Part 2)

Uber Python Interview Question

Hopefully, you've already solved Pascal's Triangle(part 1) – where we generated the first n rows of the triangle. Now, let’s put a twist on that problem for part 2.

Imagine you are still working with Pascal's Triangle, but instead of generating multiple rows, you're only interested in a specific one. Given the index of a row, can you compute that row directly, without generating the entire triangle?

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

Pascal's Triangle

For example, when , you should return , since the second row (index 1) of Pascal's triangle is (refer to the image above).

When , you should return , because the fourth row (index 3) of Pascal's triangle is (refer to the image above).

Input

Python

Output