Back to Practice Dashboard
Python BasicsEasy

Nth row of Pascal Triangle

Learn how to solve the 'Nth row of Pascal Triangle' problem. This detailed resource details brute force and optimized approaches.

Problem Statement

Easy

Write a function pascal_row(n) that returns the nth row of Pascal's Triangle as a list of integers using recursion. Rows are 0-indexed: row 0 is [1], row 1 is [1, 1], row 2 is [1, 2, 1], etc. Each element is the sum of the two elements directly above it in the previous row.

Constraints
  • 0 <= n <= 30

Examples

Example 1
Input
n = 0
Output
[1]
Explanation

The 0th row of Pascal's Triangle is just [1].

Example 2
Input
n = 4
Output
[1, 4, 6, 4, 1]
Explanation

Row 3 is [1,3,3,1]. Row 4: 1, (1+3)=4, (3+3)=6, (3+1)=4, 1.

Example 3
Input
n = 2
Output
[1, 2, 1]
Explanation

Row 1 is [1,1]. Row 2: 1, (1+1)=2, 1.

Need a Hint?
Use simple arithmetic operators (like modulo `%`, division `//`), conditional checks, or loops to inspect number properties.
Edge Cases to Watch
  • Empty list or null input variables
  • Single item lists/arrays
  • Extremely large input bounds causing integer or stack overflow

Ready to Solve?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

Open in Editor