Given a row number (0-indexed), generate that row of Pascal Triangle. Row 0 is [1], row 1 is [1, 1], row 2 is [1, 2, 1], row 3 is [1, 3, 3, 1], and so on. Each element is the sum of the two elements directly above it in the previous row. Return null for null input and an empty list for negative row numbers.
Examples:
Input: rowNum = 0
Output: [1]
Explanation: Row 0 is the apex of the triangle, always containing just [1]
Input: rowNum = 4
Output: [1, 4, 6, 4, 1]
Explanation: Row 4 has 5 elements built from row 3 ([1, 3, 3, 1])
Input: rowNum = 1
Output: [1, 1]
Explanation: Row 1 always contains two 1s
Input: rowNum = null
Output: null
Explanation: Null input returns null
Input: rowNum = -1
Output: []
Explanation: Negative row numbers return an empty list
Apex Code Editor
Welcome to Lightning Challenge!
Create an Account
Sign up to track your progress, earn points, and compete with others. Your solutions will be saved automatically.
Create accountHow It Works
- • Write your solution in the code editor
- • Connect your Salesforce org to test
- • Submit to check if your solution passes
- • Use hints if you get stuck
Contest Alert
🏆 #CodeEveryDay Mar/April 2026
Contest runs March 3 - April 30. Complete challenges to climb the leaderboard!
Points are calculated for challenges completed during the contest period.