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!
How 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 November 2026 (Nov 16–30)Sponsored by FLXBL
Contest runs November 16 - 30. Complete challenges to climb the leaderboard!
Prizes 1 & 2: Salesforce certification exam voucher — won by random drawing, where every point is a ticket. see all prizes
Only the 15 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.