Lecture40: Rat in a Maze Problem || C++ Placement Course 2022

preview_player
Показать описание
In this Video, we are going to continue exploring a very important concept i.e. Recursion.

There is a lot to learn, Keep in mind “ Mnn bhot karega k chor yrr apne se nahi yoga ya maza nahi aara, Just ask 1 question “ Why I started ? “

Question Links:

Do provide you feedback in the comments, we are going to make it best collectively.

Connect with me here:

Telegram Group Link: Love Babbar CODE HELP

Intro Sequence: We have bought all the required Licenses of the Audio, Video & Animation used.

Timestamps:

00:00 - Introduction
00:33 - Question [Rat in a Maze Problem]
03:30 - Promotion
04:21 - Approach
14:43 - Code
23:21 - Dry Run
28:15 - Recursion Tree

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

Congratulations To Code Help Family
We have successfully completed
40 lectures of DSA
40++ hours fresh content 💥
"In last 56 days from 15 Nov 2021
Mene iss channel se itna kuch shikha he jitna mene apni poori college life me nhi shikha."

Thanks to One & Only mr. Love Babbar Sir( Babbar bhaiya❤️ ) ....
*Babbar* shirf naam hi nhi kaam bhi bolta he

Ayush_.
Автор

10 day recursion challenge completed, despite of you being covid positive.
This shows how consistent you are, and how you do what you say, whatever situation may come.
That's why I #believeinBabbar .
Hats off to you, bhaiya.

It feels great watching your new video everyday when it comes, with you I am also trying to be consistent.
Thank You.

aryan
Автор

itne hard que ko itni easy tarike se samjha diya .. mere chote se dimaag me halchal mach gai😂

Ayush_.
Автор

No one can come close to quality and consistency of your content. Thank u bhaiya.

chaitanyasawant
Автор

class Solution{
private:
bool isSafe(vector<vector<int>> &m, int n, int x, int y, vector<vector<int>> visited){
if((x>=0 && x<n) && (y>=0 && y<n) && m[x][y]==1 && visited[x][y]==0){
return true;
}
else{
return false;
}
}

void solve(vector<vector<int>> &m, int n, int x, int y, string path, vector<string>& ans,
vector<vector<int>> visited){

//base case --->reached at destination
if(x==n-1 && y==n-1){
ans.push_back(path);
return ;
}

visited[x][y]=1;

//down
int newx = x+1;
int newy = y;
if(isSafe(m, n, newx, newy, visited)){
path.push_back('D');
solve(m, n, newx, newy, path, ans, visited);
path.pop_back();
}

//Left
newx = x;
newy = y-1;
if(isSafe(m, n, newx, newy, visited)){
path.push_back('L');
solve(m, n, newx, newy, path, ans, visited);
path.pop_back();
}

//Right
newx = x;
newy = y+1;
if(isSafe(m, n, newx, newy, visited)){
path.push_back('R');
solve(m, n, newx, newy, path, ans, visited);
path.pop_back();
}

//Up
newx = x-1;
newy = y;
if(isSafe(m, n, newx, newy, visited)){
path.push_back('U');
solve(m, n, newx, newy, path, ans, visited);
path.pop_back();
}


visited[x][y]=0; //backtracking
}
public:
vector<string> findPath(vector<vector<int>> &m, int n) {

// 0---> not allowed
// 1--->allowed

vector<string> ans;

//not allowed at starting coordinate
if(m[0][0]==0){
return ans;
}

//starting coordinate
int srcx =0;
int srcy =0;


vector<vector<int>> visited = m;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
visited[i][j]=0;
}
}


string path="";
solve(m, n, srcx, srcy, path, ans, visited);
sort(ans.begin(), ans.end());
return ans;

}
};

sahilwagh
Автор

Best explanation Bhaiya😁. Itne aache se recursion tree kisi ne nahi samjhaya hai. This series is like life saver for me becuz I am currently pursuing electrical engineering but my interests are in BlockChain Development and problem solving. So your videos are not just helping the CSE students. Its reaching and helping to all the students who wants to enter in the software industry and follow their passion.

ayushraj
Автор

Mast Samjhaya aapne bhaiyya.
Yes Recursion and BackTRacking bohot Tough lagta ha humko. Bohooot Practice karna hoga.
But Explained Exceptionally well!

mdwaqar
Автор

you wont believe, on the start of the lecture i thought to give it a try by myself and I was able to solve express my love for you in words finally i can do recursion problems

shubhamkhati
Автор

i am SDE-2 @Global Payments Inc, (TSYS) Noida. Following all your videos in this series. Had started 1 month ago. was able to solve this Problem without seeing your solution based on the concepts developed in the last 9 lectures. Great videos

pranavsingh
Автор

yarr bhaiya kya mast consistency hai aapke course ki, maza aa gya🤩🤩
Although me yaha tk pahucha nahi but aapki consistency dekh kar motivate ho jata hu.😊

aryanjha
Автор

faad explaination...itni kushi...itni kushi mujhe aaj tak nahi hui... bhaiiya kya samjhaya hai ye, samajh aajane ki kushi me kya kya likhdu me.... Maje aagye bhaiya😁

animallover
Автор

Awesome explanations bhaiya, 2 years since the series started but still best on youtube💯💯🔥🔥

bitsat
Автор

Kya samjhaya hai bhai maza aa gya, itna ache se jo last mein dry run ki that was much needed.

hypedpandaa
Автор

kya hi hawwa bana ke rakha rha logo ne rate in a maze ka !!!
bhaiya maza hi agya !!
thank you so much !!

venomhighs
Автор

itne dedication se to koi bhi nahi samjha sakta ....hats

manavsharma
Автор

i watched your video on advanced binary search where you covered questions like roti pratha, painter's partition and aggressive cows.I loved your explanation.
It only took me book allocation problem to properly understand, after that i was able solve to all the other questions without looking at their explanations.
however, i watched the whole video to make sure i was not missing any important analysis or anything like that.

anujkhare
Автор

Koi mjhe bata skta h ki 15:12 pe sir ne visited vector ko create krte huye use m se q equalize kiya ...m confused

ellis-prhh
Автор

I was doing everything right, just stucked in infinite recursions because of 1, 1, 1... everywhere. Thanks for 8:43 you solved my problem!

subhamahir
Автор

Samaj gaya bhaiya. Bohat badhiya explanation tha. First time ye problem dekha maine aur usi me samj gaya approach kya hona chahiye. Thank you so much!

meeninathdhobale
Автор

Brother... Crystal clear explanation 🤍🤍✨✨ World's best explanation to this problem 🧡✨
Thanks a lot Babbar Bhaiya 🧡✨

theelitecoder