Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
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.
Code
Sign up free to run your codeLog inLn 2
Run your code to see test output here.