Python BasicsEasy

Nth row of Pascal Triangle

Detailed guide and Python implementation for the 'Nth row of Pascal Triangle' problem.

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?
Consider using Recursion-specific data structures like sets or heaps.
Edge Cases to Watch
  • Empty input structures
  • Single element inputs
  • Large numerical bounds

Ready to Solve?

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

Open in Editor

Recommended Python Resources

Expand your knowledge with related interactive tutorials, cheat sheets, and code comparisons.