1219. Path with Maximum Gold | Backtracking | Recursion

  Рет қаралды 3,166

Aryan Mittal

Aryan Mittal

Күн бұрын

Пікірлер: 25
@ARYANMITTAL
@ARYANMITTAL 6 ай бұрын
14 + 9 is 23 & not 24 🌚 Complete Backtracking Guide - kzbin.info/www/bejne/ooPMfnqliLF2na8
@SaurabhSingh-fw1qn
@SaurabhSingh-fw1qn 20 күн бұрын
Bhai exceptional skills !!!
@thehappydeveloperguide
@thehappydeveloperguide 3 ай бұрын
Very good. Thank you !
@adityajhunjhunwala9739
@adityajhunjhunwala9739 6 ай бұрын
bro 3 ^ 25 will give TLE then how it can be the Time Complexity
@bhavaygoel
@bhavaygoel 6 ай бұрын
hey aryan, glad you are fine! nice vid
@subhashreddy5391
@subhashreddy5391 6 ай бұрын
Great Explanation, But I didnt get the reason why we can't apply DP? Could you please clarify?
@ARYANMITTAL
@ARYANMITTAL 6 ай бұрын
For Dp we memoize something, that is something which is being repeated again and again, in these kind of 4 directional traversal problems when there is no parameter to go uni - directional, then there is nothing we can memoize ( memoize needs some start point, from which we store answer), here firstly we try every start point & second try all possibilities as everything is different & for a path answer, it is already stored and returned via a dfs. Longest increasing path in a matrix, it is a good problem to compare and see what directional traversal in 4 directional traversal looks like. I hope that explains ❤️❤️
@subhashreddy5391
@subhashreddy5391 6 ай бұрын
@@ARYANMITTAL Definitely. Thank You!
@paras6079
@paras6079 6 ай бұрын
Bhai Square Root Decomposition kya hota hai ? Video bana sakte ho. Iski importance hai kya waise OA's ke liye ? i think ye Query wale problems ke liye use mein aati hai
@rohit_700
@rohit_700 6 ай бұрын
Aryan Bro, The explanation is as always good. I have one doubt, why are you taking dx and dy array with four values?? let's say my current i=1 , j=1; and dx=-1 and dy =-1 Then accourding to your logic ni = 1-1 =0 ny = 1-1 =0 from (1,1) -> (0,0) we have to take the horizontal path, which is not allowed. for (1,1) you can only choose to go to below valid points up (0,1) down (2,1) left (1,0) right (1,2) can you please explain this??
@rohit_700
@rohit_700 6 ай бұрын
Okay, that is not double for loop. so it will only take value sin single pass.
@codencode5546
@codencode5546 6 ай бұрын
You'll never encounter a diagonal value because we are going in only 4 direction. and there is no such pair of {dx,dy} which leads to {-1,-1}
@worldofgaming748
@worldofgaming748 6 ай бұрын
I praise you for explaining this clearly but when i see moments like this 13:49 ill be like Nah bro🐼
@anshadarsh1194
@anshadarsh1194 6 ай бұрын
why are we suning dx and dy stuff containing 0,1 and -1 ??
@kandariarjun
@kandariarjun 6 ай бұрын
To go to the 4 diff directions.
@aizad786iqbal
@aizad786iqbal 6 ай бұрын
bfs approach please ?
@gilfoyle2211
@gilfoyle2211 6 ай бұрын
chalo zinda hai Aryan😂😂😭😭
@ARYANMITTAL
@ARYANMITTAL 6 ай бұрын
🕵
@mukulkhanna5071
@mukulkhanna5071 6 ай бұрын
I have solved this problem by creating visited array for each i,j but it is failing here is the code please let me where i am going wrong class Solution { public: int n,m; vectorgr; vectordirs={{0,1},{0,-1},{1,0},{-1,0}}; int dfs(int i,int j,bool vis[16][16]){ if(i=n||j=m||gr[i][j]==0||vis[i][j]==true)return 0; vis[i][j]=true; int ans=gr[i][j]; int maxi=0; for(int k=0;k
@vikaskumarnitrr
@vikaskumarnitrr 6 ай бұрын
what is wrong in this code 45 test case passed class Solution { public int getMaximumGold(int[][] grid) { int ans = 0; for(int i=0; i
@LOKESHE-wi2yd
@LOKESHE-wi2yd 6 ай бұрын
is that the testcase had output as 60 and did you got 58 or what
@LOKESHE-wi2yd
@LOKESHE-wi2yd 6 ай бұрын
maybe its because we are marking the visited of a cell as true that not actually yet visited in current path , i too made the same mistake public int dfs(int[][]grid,boolean[][]visited,int r,int c,int sum){ if(r=grid.length||c=grid[r].length){ return sum; } if(visited[r][c]||grid[r][c]==0){ return sum; } visited[r][c] = true; sum+=grid[r][c]; return Math.max( dfs(grid,visited,r+1,c,sum), Math.max(dfs(grid,visited,r-1,c,sum), Math.max(dfs(grid,visited,r,c+1,sum), dfs(grid,visited,r,c-1,sum) ) ) ); }
@LOKESHE-wi2yd
@LOKESHE-wi2yd 6 ай бұрын
class Solution { public int getMaximumGold(int[][] grid) { int ans = 0; for(int i=0; i
@sivalokesh3997
@sivalokesh3997 6 ай бұрын
@@LOKESHE-wi2yd Good find bro.
@sivalokesh3997
@sivalokesh3997 6 ай бұрын
20+2+4+7+6+5+3+4+3+1+5. This is the Path for Answer. For your failed testCase. Now understand yourself where it can go wrong.
2751. Robot Collisions | Stack | Sorting | Not Hard 🫡
19:30
Aryan Mittal
Рет қаралды 6 М.
How To Choose Mac N Cheese Date Night.. 🧀
00:58
Jojo Sim
Рет қаралды 89 МЛН
Path with Maximum Gold - Leetcode 1219 - Python
14:53
NeetCodeIO
Рет қаралды 9 М.
Coding Unbreakable Encryption in C | One-Time Pad
17:42
HirschDaniel
Рет қаралды 4,4 М.
Path with Maximum Probability - Leetcode 1514 - Python
13:11
NeetCodeIO
Рет қаралды 14 М.
Delete Leaves With a Given Value - Leetcode 1325 - Python
14:45
Google Coding Interview Question - Path With Maximum Gold (LeetCode)
17:24
1861. Rotating the Box | Simulation | 2 Pointers
17:00
Aryan Mittal
Рет қаралды 883