Leetcode 62. Unique Paths || Code + Explanation

preview_player
Показать описание
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).

The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below).

How many possible unique paths are there?
Input: m = 3, n = 7
Output: 28
Example 2:

Input: m = 3, n = 2
Output: 3
Explanation:
From the top-left corner, there are a total of 3 ways to reach the bottom-right corner:

Example 3:

Input: m = 7, n = 3
Output: 28

Рекомендации по теме
Комментарии
Автор

love the way u make everything easier when i practice on leetcode i just watch 2 channels: ur channel and neetcode. Thanks a lot

nguyenbach
Автор

Supper explaintion, never understood any solution so fast.

nikhil
Автор

thanks for the explanation, you are great, great approach and great solution, really appreciated.

SoumojitKoley-sdje
Автор

nice explaination.
can u explain the problem where movement is possible from all 4 directions but revisit isnt allowed

vinaykenguva
Автор

Declare vector of vectors initially all grid value 1 for loop start with I and j for column dp I and j is equal to I minus 1 and j and same j minus 1 returns because last node

Zedxwhy
Автор

Very good explanation. Thank you Alisha!

jkali-pgfh
Автор

mam plz do space optimization too.
super explanation

_adarshprajapati
Автор

Thank you for this wonderful explanation😄

pankajchadda
Автор

thanks for such a wonderful explanation

vyankateshkulkarni
Автор

3 suggestions :
1. At the end please mention the time complexity and space complexity
2. Can we start from recursion and then memorization and then dp solution . In this way, we can prove why we are using dynamic programming for this solution ( as we can see overlapping problem while drawing recurrence tree )
3. Currently we are using 2 D matrix (dp) to store the ans . We can optimise it to two 1 D matrix as we only need previous row and current row

piyush
Автор

Vector of vector mai(n, 1) ka kya meaning

bhooviarora
visit shbcf.ru