Math Pascal's triangle and combinations
102. Pascal's Triangle Value
Medium
In Pascal's triangle, rows and columns are counted from 0. Row 0 is the single 1 at the top, and column 0
is the first value of every row. So row 4 is 1 4 6 4 1, and its column 2 holds 6.
Given two integers row and col, return the value in row row, column col.
Example 1
Input: row = 6, col = 2
Output:
15Explanation: Row 6 is 1 6 15 20 15 6 1. Counting from 0, column 2 holds 15.
Example 2
Input: row = 1000000000000000, col = 999999999999999
Output:
1000000000000000Explanation: Every row r starts with 1, r and ends with r, 1. Column 999999999999999 is the second value from the end, so it holds the row number.
Example 3
Input: row = 66, col = 33
Output:
7219428434016265740Check your understanding
Work out the answer for this input before you write any code.
row = 5, col = 2
Constraints
0 ≤ row ≤ 10150 ≤ col ≤ row- The answer fits in a signed 64-bit integer.
Clarifying questions
What you would ask an interviewer before writing any code.