Тёмный

Out of Boundary Paths - Leetcode 576 - Python 

NeetCodeIO
Подписаться 153 тыс.
Просмотров 15 тыс.
50% 1

🚀 neetcode.io/ - A better way to prepare for Coding Interviews
🧑‍💼 LinkedIn: / navdeep-singh-3aaa14161
🐦 Twitter: / neetcode1
⭐ BLIND-75 PLAYLIST: • Two Sum - Leetcode 1 -...
Problem Link: leetcode.com/problems/out-of-...
0:00 - Read the problem
0:30 - Drawing Recursive solution
5:23 - Coding Recursive
8:59 - Drawing DP solution
12:35 - Coding DP solution
leetcode 576
#neetcode #leetcode #python

Опубликовано:

 

25 июл 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 27   
@AMakYu
@AMakYu 6 месяцев назад
That 3D DP solution is wild. I was able to get the memoization solution on my own today, but I still have trouble translating that into bottom up approaches. But honestly, I've come a long ways already for being able to solve a problem like this by myself with memo. Thanks Neet!
@zaki_1337
@zaki_1337 6 месяцев назад
is it necessary to learn the iterative solutions? do interviewers ask that?
@aswinnath8580
@aswinnath8580 6 месяцев назад
they will mostly expect that one if you give only the memo one there is no guarantee you will pass the round unless if its a very hard dp problem or not a trivial one. @@zaki_1337
@AMakYu
@AMakYu 6 месяцев назад
@@zaki_1337 I think it depends on your interviewer. I think most would probably accept memo, but I had a friend who had a TikTok interview where he tried memo for a problem but it was hitting a stack limit, indicating that they wanted the bottom up approach.
@zaki_1337
@zaki_1337 6 месяцев назад
@@AMakYu oh :/
@vm1662
@vm1662 6 месяцев назад
3D DP it is! I was thinking in terms of 2D and didn't know how to memoize it. Thanks NeetCode!
@firehouse1395
@firehouse1395 6 месяцев назад
Your solutions are so real, nothing fancy, they are simple and easy to understand
@felixx2012
@felixx2012 6 месяцев назад
Thanks for doing these daily problems. Very helpful
@pastori2672
@pastori2672 6 месяцев назад
i actually got MLE on a bfs solution and a TLE on the dfs one xd
@legendary5320
@legendary5320 6 месяцев назад
One thing I was confused about the recursive brute force solution is that why are we allowed to go back to the node we just came from? Would that not consitute a path?
@MP-ny3ep
@MP-ny3ep 6 месяцев назад
Great explanation as always. Thank you .
@gmh14
@gmh14 6 месяцев назад
You mentioned a BFS solution wouldn't work but in one of my approaches I considered it and it somehow worked. Gave TLE at 22/94 but it could possibly be optimized? # BFS solution MOD = 10**9 + 7 directions = [(0, -1), (0, 1), (-1, 0), (1, 0)] queue = [(startRow, startColumn, maxMove)] res = 0 while queue: node_i, node_j, curMoves = queue.pop(0) if curMoves > 0: curMoves -= 1 for delrow, delcol in directions: new_i, new_j = node_i + delrow, node_j + delcol if not (0
@EduarteBDO
@EduarteBDO 6 месяцев назад
The second solution is less efficient in LC because we are calculating the possibilities for all positions in the grid. Different from the dfs solution were we calculate for the startRow/startCol, but in a case where we wanted to calculate all of them the DP is much more faster and memory efficient.
@sankalpchordia5245
@sankalpchordia5245 6 месяцев назад
Well explained
@priyanshuganatra
@priyanshuganatra 6 месяцев назад
Memoization solution is pretty straightforward, I dunno bout da tabu sol tho
@krateskim4169
@krateskim4169 6 месяцев назад
Thank you so much
@rostislav_vat
@rostislav_vat 4 месяца назад
thanks, man
@Kaviarasu_NS
@Kaviarasu_NS 6 месяцев назад
Thanks ❤
@unknown-ut5qn
@unknown-ut5qn 6 месяцев назад
always on top
@shashankjoshi8250
@shashankjoshi8250 6 месяцев назад
For a Brute Force Memoization I am getting TLE.
@sankalppatil2994
@sankalppatil2994 6 месяцев назад
💪💪
@XEQUTE
@XEQUTE 6 месяцев назад
day 26 Leetcode
@walkastray007
@walkastray007 6 месяцев назад
Not to brag NeetCode, but I got the 15 view on this video.
@SC2Edu
@SC2Edu 6 месяцев назад
did you solve it at least? :D
@EduarteBDO
@EduarteBDO 6 месяцев назад
for the if statments I mada a helper function: class Solution: def findPaths(self, m: int, n: int, maxMove: int, startRow: int, startColumn: int) -> int: ROWS,COLS = m,n MODULO = pow(10,9)+7 curGrid = [[0] * COLS for _ in range(ROWS)] prevGrid = [[0] * COLS for _ in range(ROWS)] def helper(r,c): if r < 0 or c < 0 or r == ROWS or c == COLS: return 1 return prevGrid[r][c] for _ in range(maxMove): for r in range(ROWS): for c in range(COLS): val = helper(r+1,c) val += helper(r-1,c) val += helper(r,c+1) val += helper(r,c-1) val %=MODULO curGrid[r][c] = val prevGrid, curGrid = curGrid,prevGrid return prevGrid[startRow][startColumn]
@shaco6630
@shaco6630 6 месяцев назад
Great explanation as usual! A suggestion, is it not a bit more readible to remove the if/else checks with something similar to this? (I added this vcrsion to neetcode github if that's ok, instead of having all the if statements) class Solution { fun findPaths(m: Int, n: Int, maxMove: Int, startRow: Int, startColumn: Int): Int { val mod = 1_000_000_007 val dirs = intArrayOf(0, 1, 0, -1, 0) val dp = Array (m) { Array (n) { LongArray (maxMove + 1) } } for (k in 1..maxMove) { for (i in 0 until m) { for (j in 0 until n) { for (dir in 0..3) { val i2 = i + dirs[dir] val j2 = j + dirs[dir + 1] if (i2 < 0 || i2 == m || j2 < 0 || j2 == n) dp[i][j][k]++ else dp[i][j][k] = (dp[i][j][k] + dp[i2][j2][k - 1]) % mod } } } } return dp[startRow][startColumn][maxMove].toInt() } }
Далее
K Inverse Pairs Array - Leetcode 629 - Python
29:44
Просмотров 15 тыс.
Базовый iPhone 16
00:38
Просмотров 215 тыс.
Understanding Ownership in Rust
25:31
Просмотров 247 тыс.
Big-O Notation - For Coding Interviews
20:38
Просмотров 433 тыс.
Longest Ideal Subsequence - Leetcode 2370 - Python
28:02
1v1 Coding Lockout Championship Finals
3:37:39
Просмотров 77 тыс.
Most Common Concepts for Coding Interviews
6:08
Просмотров 290 тыс.