oneby7

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: 15

Explanation: 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: 1000000000000000

Explanation: 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: 7219428434016265740

Check your understanding

Work out the answer for this input before you write any code.

row = 5, col = 2

Constraints

  • 0 ≤ row ≤ 1015
  • 0 ≤ col ≤ row
  • The answer fits in a signed 64-bit integer.

Clarifying questions

What you would ask an interviewer before writing any code.

Hints

Interview follow-ups

Runs in your browser
Code
Runs in your browser for now · some things may not work as expectedLn 1, Col 1

Article

Send feedback

Thank you for helping. We read every report and fix what is wrong.

How do you feel about oneby7?

Sign in to oneby7

Keep your progress, your streak and your code, on any device.

New here? This creates your account too.