Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Unique Grid Path Combinations
00:00
5 left

Unique Grid Path Combinations

HardPython

Problem

A Wealthfront interface models a navigation flow as an n x m grid. Starting at the top-left cell, a user may move only one cell right or one cell down. Return the total number of distinct paths to the bottom-right cell.

The result must be exact. Do not construct the full grid or use a recursive solution that recomputes the same states.

Formal Specification

Implement unique_paths(rows, cols), where rows and cols are positive integers. Return an integer equal to the number of valid paths from (0, 0) to (rows - 1, cols - 1).

A valid path contains exactly rows - 1 down moves and cols - 1 right moves. Since the answer can be very large, use Python's arbitrary-precision integers.

Constraints

  • 1 <= rows, cols <= 100000
  • rows and cols are integers
  • The exact result must be returned
  • Additional space must be less than O(rows * cols)

Function Signature

def unique_paths(rows, cols):
Interviewer

Your question is Unique Grid Path Combinations. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.