A robot is placed at the top-left corner of an m x n grid and needs to reach the bottom-right corner. The robot can only move right or down at each step. Return the total number of unique paths from the top-left to the bottom-right corner.

Return null if either m or n is null.

Example 1:

Input: m = 3, n = 7 Output: 28 Explanation: There are 28 unique paths in a 3x7 grid moving only right or down.

Example 2:

Input: m = 3, n = 2 Output: 3 Explanation: Three unique paths exist in a 3x2 grid.

Example 3:

Input: m = 1, n = 1 Output: 1 Explanation: The robot is already at the destination, so there is exactly 1 path.

Example 4:

Input: m = 1, n = 5 Output: 1 Explanation: In a single-row grid, the robot can only move right. There is only 1 path.

Example 5:

Input: m = null, n = 7 Output: null
Apex Code Editor

Welcome to Lightning Challenge!

How It Works

  • • Write your solution in the code editor
  • • Connect your Salesforce org to test
  • • Submit to check if your solution passes
  • • Use hints if you get stuck

Contest Alert

🏆 #CodeEveryDay August 2026

Contest runs August 1 - 31. Complete challenges to climb the leaderboard!

Only the 31 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.

Wally can't hear you

Please sign in to access the AI Assistant

Sign In