Pascal's Triangle II

EasyDynamic Programming1d dp

Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.

Practice this as a mock interviewFree to start, no account needed

Problem

In Pascal's triangle, each row starts and ends with 1, and every inner entry is the sum of the two entries directly above it. Rows are **0-indexed**: row 0 is [1], row 1 is [1,1], row 2 is [1,2,1]. Given rowIndex, return that row as an array of rowIndex + 1 integers. Try to use only O(rowIndex) extra space.

Examples

Input: rowIndex = 3
Output: [1,3,3,1]
Row 2 is [1,2,1]; adding neighbours gives [1,3,3,1].
Input: rowIndex = 0
Output: [1]
Row 0 is a single 1.

Constraints

  • 0 <= rowIndex <= 33
  • The row is 0-indexed.
  • All values fit in a 32-bit signed integer.

What the interviewer grades

A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.

More 1d dp problems