Leetcode 2435. Paths in Matrix Whose Sum Is Divisible by K |Dynamic Programming| Weekly Contest Hard

  Рет қаралды 5,347

Code with Alisha

Code with Alisha

Күн бұрын

Пікірлер: 38
@probabilitycodingisfunis1
@probabilitycodingisfunis1 2 жыл бұрын
int mod = 1e9+7; int numberOfPaths(vector& grid, int k) { vectordp(grid.size(), vector( grid[0].size(), vector(51,-1))); return fnc(grid, k, 0, 0, 0, dp); } int fnc(vector& grid, int k, int i,int j, int sum, vector&dp) { //base conditions if(i=grid[0].size()) { return 0; } //end cell of grid if(i==grid.size()-1 && j==grid[0].size()-1) { sum+=grid[i][j]; if(sum%k==0)return 1; return 0; } if(dp[i][j][sum%k]!=-1)return dp[i][j][sum%k]; long down = fnc(grid, k, i+1, j, sum+grid[i][j],dp); //down long right = fnc(grid, k, i, j+1, sum+grid[i][j], dp); //right return dp[i][j][sum%k] = (down%mod +right%mod)%mod; }
@myitraju7996
@myitraju7996 2 жыл бұрын
i m beginner,is it good to start my coding journey direct from leetcode?
@yaswanthkosuru
@yaswanthkosuru 2 жыл бұрын
@@myitraju7996 yaa absolutely
@myitraju7996
@myitraju7996 2 жыл бұрын
@@yaswanthkosuru thanks 😊
@asishmaity884
@asishmaity884 2 жыл бұрын
are didi java se karwao plss
@utkarsh_ishan
@utkarsh_ishan 2 жыл бұрын
Please don't stop making videos on leetcode contests. Your explanation for contests is by far the best I have ever seen
@AbhishekKumar-qy1ek
@AbhishekKumar-qy1ek 2 жыл бұрын
Thank you didi. Please make a video of third problem i.e using a robot to print the lexicographically Smallest string.
@AbhishekSingh-l9i
@AbhishekSingh-l9i 4 ай бұрын
may god bless you and your channel
@stupidbutcurious6206
@stupidbutcurious6206 2 жыл бұрын
very well explained... i came across this question while searching for another similar question... can you please help solve.. The Question is:- Given an array of integers of size N, count all possible distinct triplets whose sum is exactly divisible by given integer K. for triplets i, j, k --> i
@ankitpandey64
@ankitpandey64 2 жыл бұрын
if I don't understand from anywhere you always help me, always great explanation thank you
@AyushKumar-rh1vy
@AyushKumar-rh1vy 2 жыл бұрын
Great explanation, Thanks for your effort 🔥
@barathnatarajan8566
@barathnatarajan8566 2 жыл бұрын
HEY sis, i got placed at a company for 10lpa base. thank u so much for ur DSA videos . It helped me a lot
@probabilitycodingisfunis1
@probabilitycodingisfunis1 2 жыл бұрын
Congratsss, all the best for your future!
@reshmaparveen6679
@reshmaparveen6679 2 жыл бұрын
Great job di
@millybrown5168
@millybrown5168 2 жыл бұрын
why do we need to memoize the rem ?? i tried doing this using 2d dp but it didn't work. don't know where I'm going wrong int num(vector& grid, int &k,int i,int j,int sum,vector &dp){ if(i
@probabilitycodingisfunis1
@probabilitycodingisfunis1 2 жыл бұрын
@Mily, it will give wrong answer. consider the example [[1,2,3],[4,5,6],[7,8,9]] and k = 5, when you calculate for i=1,j=1 ,(grid[i][j]=5), for the path 1->2->5->8->9 gives sum=25 and sum%k==0 (because k=5), so you will store dp[i][j]=1 for this cell, so when you come to next function call in this cell at i=1,j=1 ,(grid[i][j]=5), for the path 1->2->5->6->9, the actual sum is 23, which means 23%5 !=0, but since you will not go to the complete path 1->2->5->6->9 using recursion, rather get your saved answer from dp[1][1] which tells you that it is 1 , you will stop there and consider answer to be 1 for this path also which is wrong, hence according to your code you will not get correct answer, you need to check for sum also ( new paths at each coordinate may have different sum than before which may not give answer)
@millybrown5168
@millybrown5168 2 жыл бұрын
@@probabilitycodingisfunis1 understood, thank you so much
@abhinavverma4111
@abhinavverma4111 2 жыл бұрын
Wonderful Explanation. Can you suggest a similar problem to 3D dp?
@Idukhan-jj9kc
@Idukhan-jj9kc 2 жыл бұрын
Best solution Alisha 👌😉
@midhileshmomidi3120
@midhileshmomidi3120 2 жыл бұрын
Best solution
@ayushsinghrathore360
@ayushsinghrathore360 2 жыл бұрын
Ma'am plzz Reply.... Ma'am Aap all approaches btate ho And they are really good but for the popular question which tells us new approaches to aap uski approach khud se hi discover krte ho ya aapko bhi kayi baar dekhna hota h efficient approach.
@ayushsinghrathore360
@ayushsinghrathore360 2 жыл бұрын
For example if we are new and solve snake and ladder problem toh khud se pura sochna muskil hota h same goes with special or popular questions which needs some different and new approach.
@ayushsinghrathore360
@ayushsinghrathore360 2 жыл бұрын
Add a Reply plzz
@rishav144
@rishav144 2 жыл бұрын
@@ayushsinghrathore360 bro , new approach khud se sochne ka try kro...bcoz Interviewer will tell u to optimize time and space complexity ......Pehle regular approach se solve kro....phir new approach try kro ...try for 20-30 mins ....then u may refer editorials or video solns if unable to solve through new or optimized approaches
@galibkiyaadein4627
@galibkiyaadein4627 Жыл бұрын
Koi khud se nhi sochta kuch bro to be honest sab standard practice kar karke. Yddd mar lete hai
@omkarkadam309
@omkarkadam309 8 ай бұрын
"annnd listening" in the end is hilarious
@pujarisanthoshbabu4073
@pujarisanthoshbabu4073 2 жыл бұрын
Kudos to your hardwork
@ROHITKADYANJI
@ROHITKADYANJI 2 жыл бұрын
Maam continuosly getting rejected some times in tr ,hr, coding round how to handle this please help
@amangaur4231
@amangaur4231 2 жыл бұрын
You are best
@rishav144
@rishav144 Жыл бұрын
pls dont stop uploading videos of leetcode questions😣
@probabilitycodingisfunis1
@probabilitycodingisfunis1 Жыл бұрын
Will start soon again, thanks 👍
@rishav144
@rishav144 Жыл бұрын
@@probabilitycodingisfunis1 thanks ...your Leetcode videos are really helpful
@tejasahuja7133
@tejasahuja7133 2 жыл бұрын
Nice solution, just one request to please increase frequency of your videos
@AmanSharma-vb5jl
@AmanSharma-vb5jl 2 жыл бұрын
I don't have words to describe, only i can say "waah waah Kamal kr diya dhoti ko faad kr rumal kr diya" You are seriously awesome.
@shubamgoswami
@shubamgoswami 2 жыл бұрын
Fun fact 3rd one is harder than the 4th one waiting for 3 and welcome back 🥳
@mayanksoni9046
@mayanksoni9046 2 жыл бұрын
You are returning 1 and 0 while question is asking total number of paths. Can u explain How they are getting added please.
@AbhishekPandey-yl3bp
@AbhishekPandey-yl3bp 2 жыл бұрын
When you need the total count of something,you need to return 1 or 0 in the base case so it'll keep adding up to give the total count
@rahulbhardwaj4380
@rahulbhardwaj4380 2 жыл бұрын
this was great question! thanks for the explanation! And please accept my request on linkedin 😅
AVL Trees & Rotations (Self-Balancing Binary Search Trees)
20:38
Back To Back SWE
Рет қаралды 348 М.
PIZZA or CHICKEN // Left or Right Challenge
00:18
Hungry FAM
Рет қаралды 15 МЛН
1, 2, 3, 4, 5, 6, 7, 8, 9 🙈⚽️
00:46
Celine Dept
Рет қаралды 88 МЛН
Leetcode 2401. Longest Nice Subarray | Weekly Contest 2401.
19:54
Code with Alisha
Рет қаралды 6 М.
Leetcode 2392. Build A Matrix With Conditions | Weekly Contest 308.
27:46
Code with Alisha
Рет қаралды 3,4 М.
Leetcode 894. All Possible Full Binary Trees
29:08
Code with Alisha
Рет қаралды 4,3 М.
How Senior Programmers ACTUALLY Write Code
13:37
Thriving Technologist
Рет қаралды 1,6 МЛН
SubMatrix Sum using arrays || C programming
36:01
JustAnotherProgrammer
Рет қаралды 13
Weekly Contest 312  |  2421. Number of Good Paths
24:01
codingMohan
Рет қаралды 7 М.
PIZZA or CHICKEN // Left or Right Challenge
00:18
Hungry FAM
Рет қаралды 15 МЛН