Let's continue the habit of commenting “understood” if you got the entire video. Please give it a like too, you don't 😞 Do follow me on Instagram: striver_79
bhiya why cant we have no visited matrix in this soln,we can use the matrix given to us and to record the visited we can change it to '1' and while backtracking we can undo the changes
I am so happy to share that from lec 9 10 12 13 14 . I am able to solve them by myself without watching the whole video. After my solution gets accepted . I come and watch your video at 2x
The logic was really great. We instead of finding who will be marked cross , we found out who will not through the boundary connection condition . Kudo striver for making this series.
You've worked really hard to make these videos, mainly without getting irritated, you've coded each and every part. I realised how much time and PATIENCE is required to do that.... Thanks a lot
Yeah, this is the best thing about Striver's videos!! He is EXTREMELY PATIENT while explaining any logic and coding it up till the end!! Just follow his recursion series, you will get to know how much patient he can be...
saw 3 min, found intuition thanks to striver bhai and coded it, got AC, came and watched entire video to contribute to takeUForward's watch time and recommendation
I know it had something to do with border and how they connect. First attempt was to try to find which ones reach the border but then I realized it would be easier to find what ones the border reaches. From their I had it down, solved it, and watched the video as a refresher/check for tips or tricks.
i just saw your explanation of what the problem really is in the first few minutes, and then coded it using dfs and passes all the test cases on leetcode, thankyou so much striver , its due to your teaching that i am elevating my coding skills each day
My initial thoughts: start the ans matrix of size m*n with 'X's. If we have any 'O's on the boundary, treat them as a door or entrance and apply DFS from that cell. The DFS will make sure that it covers every O's cells which are connected to this entrance. Once DFS is done it would have marked all the affected cells as O's and rest are just 'X's. So in this way all the O's cells surrounded by boundary of X's will be marked as X.
19:30 I think rather than creating delRow and delCol arrays you can just mention the dfs function call 4 times. I will save a lot on the parameters per call. Code: void dfs(int row, int col, vector& mat, vector& vis) { if(row
Awesome series! Can you cover graph questions that were asked in OAs in your experience or someone else's so that we can learn what type of questions are actually asked?
striver thanks alot fot your effort in making such an amazing in depth free course , i just watched you first 6 - 7 videos and i am telling you i am able to solve medium level questions on leetcode it really boost up up confidence thanks alot striver
Oho man just did number of island Question on leetcode :) it was a daily challenge problem exactly the same type of Question like this one :) ..did with recursion went up ,down left, right and follow up the constraints :)
This question can also be done like previous one using bfs we just. Need to put zero which are at the boundary in the queue then we have to run while loop until queue becomes empty and parallely we need to mark visited to the neighbouring zeros of boundary zeros....then we have to convert zero to x which are not visited 😅
Nice explaination sir but now gfg has increased test cases to 1,120 and with this approach only 1,116 test cases are getting passed thank u for your efforts
// To traverse the boundary for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if ((i == 0 || i == n - 1) || (i > 0 and i < n - 1 and (j == 0 || j == m - 1))) { // ToDo } } }
Will it be a good practice if in dfs traversal I change the boundary connected component to some random character (suppose 'Y') and then traverse the matrix where ever I find a 'O' I convert it to 'X' and change those 'Y' back to 'O'....ultimately this will change only the required 'O' ->'X'
in order to traverse in the first row, column and last row, column we can use this ( rows & columns will have index either 0 or m-1 or n-1) for(int i =0; i < n ; i++) { for(int j = 0 ; j < m; j++) { if((i == 0 || j == 0 || i == n-1 || j == m-1)&& mat[i][j] == 'O' && vis[i][j]==0) { dfs(i,j, mat , vis,result); } } }
Hello, I also tried to solve without watching this video. Can you help me with this code, why it got stuck at 41/58 TC on leetcode :- class Solution { public: void solve(vector& board) { int n = board.size(); int m = board[0].size(); vector visited(n, vector (m,0)); vector temp(n, vector (m,'X')); queue q; for(int i = 0; i
@@flsh1343 class Solution { public: void solve(vector& board) { int n = board.size(); int m = board[0].size(); vector visited(n, vector (m,0)); vector temp(n, vector (m,'X')); queue q; for(int i = 0; i
Let's continue the habit of commenting “understood” if you got the entire video. Please give it a like too, you don't 😞
Do follow me on Instagram: striver_79
I am able to solve this question myself!! thanks a lot all this is because of you....
understood.... Best explaination
understood
bhiya why cant we have no visited matrix in this soln,we can use the matrix given to us and to record the visited we can change it to '1' and while backtracking we can undo the changes
Understood Everything Thank you so Much
I am so happy to share that from lec 9 10 12 13 14 . I am able to solve them by myself without watching the whole video. After my solution gets accepted . I come and watch your video at 2x
Same
Same
The logic was really great.
We instead of finding who will be marked cross , we found out who will not through the boundary connection condition .
Kudo striver for making this series.
kudos*
You've worked really hard to make these videos, mainly without getting irritated, you've coded each and every part. I realised how much time and PATIENCE is required to do that.... Thanks a lot
Yeah, this is the best thing about Striver's videos!! He is EXTREMELY PATIENT while explaining any logic and coding it up till the end!! Just follow his recursion series, you will get to know how much patient he can be...
saw 3 min, found intuition thanks to striver bhai and coded it, got AC, came and watched entire video to contribute to takeUForward's watch time and recommendation
the energy you bring while teaching is just amazing
I know it had something to do with border and how they connect. First attempt was to try to find which ones reach the border but then I realized it would be easier to find what ones the border reaches. From their I had it down, solved it, and watched the video as a refresher/check for tips or tricks.
love how after his all set of examples and intuitions, everything just falls in place perfectly
Honestly, Striver!! Amazing LOGIC! If we think of it like you did it becomes a walk in the park!!
UNDERSTOODD!! THANK YOUUU!!
"Understood", Marvelous explanation with high energy !!
Maza aa gya bhayiya ☺☺☺
Lg hi nhi rha tha ki hard problem kr rhe h. Aaisa level set kr dya aapne hm sbka
i just saw your explanation of what the problem really is in the first few minutes, and then coded it using dfs and passes all the test cases on leetcode, thankyou so much striver , its due to your teaching that i am elevating my coding skills each day
Striver bro!!! I just want to hug you.............lots of respect and love and keep doing what you are doing...
My initial thoughts: start the ans matrix of size m*n with 'X's. If we have any 'O's on the boundary, treat them as a door or entrance and apply DFS from that cell. The DFS will make sure that it covers every O's cells which are connected to this entrance. Once DFS is done it would have marked all the affected cells as O's and rest are just 'X's. So in this way all the O's cells surrounded by boundary of X's will be marked as X.
such a good and refined series absolutely loved it striver bhai
till now in graph series, its all about how well we have understood DFS or BFS , rest is variation !!!
Barhe log aa gye ...love you warsaw bhaiya ❤️
badhe***
YOURE MY DIAMOND STRIVES :)
I was trying to solve this question on leetcode this evening and Guess what You uploaded a solution!
Able to solve the problem just by seeing till 2:40 of the video...power of Strivers 😎
same
same
19:30 I think rather than creating delRow and delCol arrays you can just mention the dfs function call 4 times. I will save a lot on the parameters per call.
Code:
void dfs(int row, int col, vector& mat, vector& vis)
{
if(row
Time limit exceeds : 1032/1044 passed
@@arshdeep011 Are you the cricketer Arshdeep Singh?
@@rushidesai2836 I don't watch cricket
Awesome series! Can you cover graph questions that were asked in OAs in your experience or someone else's so that we can learn what type of questions are actually asked?
Bhai gfg ke jobhathon dekho almost every contest mai hard ques graph based hote hai use bhaiya samjhate hai contest review mai
@@chandannikhil8526 Thank you will check those videos out
striver thanks alot fot your effort in making such an amazing in depth free course , i just watched you first 6 - 7 videos and i am telling you i am able to solve medium level questions on leetcode it really boost up up confidence thanks alot striver
Awesome, thank you striver as always understood
because of you i am easily able to understand graph
thank you sir......
Aap question aur code dono ko bahut easy bana dete ho bhaiya😀😍
I understood your explanation, paused your video and tried it with BFS, it worked. Amazing explanation
Thank You So Much for this wonderful video............🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻
able to do this question without watching the solution it really boosted my confidence thaku striver
day by day getting confidence while doing graph question able to solve this question myself #thanks Wizard Striver
Great explanations, I was wondering here for complex problem solution I am getting training as doctor strange got from guru maa in kathmandu!
Oho man just did number of island Question on leetcode :) it was a daily challenge problem exactly the same type of Question like this one :) ..did with recursion went up ,down left, right and follow up the constraints :)
understood striver
Awesome explanation as always
thank you striver for creating such amazing content
thanks man,same question came in my cohesity interview 40lpa
Solved this one by self on BFS and DFS Both.
Graph is such a nice topic.
Understood, Thank you so much, this was such a beautiful solution.
Thank you striver for all your efforts.
excellent explanation!
Thanks a lotttt striver for such an amazing playlist
kaya bat hai baiya ,maza aagya apka obserwation se
Understood 😊
Understood!! Very well explained!!!
This question can also be done like previous one using bfs we just. Need to put zero which are at the boundary in the queue then we have to run while loop until queue becomes empty and parallely we need to mark visited to the neighbouring zeros of boundary zeros....then we have to convert zero to x which are not visited 😅
Understood bhaiya i have done bfs traversal
Great explanation 👍
Nice explaination sir but now gfg has increased test cases to 1,120 and with this approach only 1,116 test cases are getting passed
thank u for your efforts
Majaa Aagaya😜
Legend is back
Understood😁Thanks a lot Striver😃
solved on my own without watching the video on basis of prev videos and now watching
Thank you, Striver 🙂
understood, thanks for the effort on the great video
Thank you so much for such a detailed video
understood very well!!!
Thank you very much. You are a genius.
very nice approach and explanation
using jS one can make a game that contain the player which is surrounded by a protection layer and enemy can enter through the boundry points
Understood Sir, Thank you very much
Understood the solution in first 6 mins.
Paused the video and solved the question in 10 mins 😉
understood, thanks for such playlist!!
Thank You striver Bhaiya 🤟
You are my inspiration ......................hats offfffffffffffffffffffff
Thank you very much sir!!!
Understood 😀😀
Superb as usual. But the first time I found energy and excitement low during explanation.
Keep your uniqueness full of energy and excitement.❤️
Repeated questions, new questions excite me ;)
@@takeUforward 💛 thank you so much striver for these playlists , i learned recursion tree dp nd now graphs too.
// To traverse the boundary
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if ((i == 0 || i == n - 1) || (i > 0 and i < n - 1 and (j == 0 || j == m - 1))) {
// ToDo
}
}
}
#UNDERSTOOD
always love ur vidos and u brother😍
Understood 🙂
God of dsa🙏
Understood Sir!
ek dum mast
Great intuition
UNDERSTOOD!!!!!!!!
Will it be a good practice if in dfs traversal I change the boundary connected component to some random character (suppose 'Y') and then traverse the matrix where ever I find a 'O' I convert it to 'X' and change those 'Y' back to 'O'....ultimately this will change only the required 'O' ->'X'
you can! the main aim of the video is to teach that dfs or bfs can be used to solve the problem, can have various approaches.
i did the same
Thank you sir
just watched 1 min and solved the whole problem damn
Thanks you very much bro for the series
thanks striver🙌
Understood!
in order to traverse in the first row, column and last row, column
we can use this ( rows & columns will have index either 0 or m-1 or n-1)
for(int i =0; i < n ; i++)
{
for(int j = 0 ; j < m; j++)
{
if((i == 0 || j == 0 || i == n-1 || j == m-1)&&
mat[i][j] == 'O' && vis[i][j]==0)
{
dfs(i,j, mat , vis,result);
}
}
}
It has m*n complexity, our solution has m+n complexity
understood , thnk u striver
Understood❤
here we go !
Solved it without starting the video
Thank you Raj bhaiya for this wonderful playlist!
CODE:
class Solution {
private:
int dir[5] = {0,-1,0,1,0};
void bfs(int r, int c, vector &board, vector &safe){
safe[r][c] = true;
queue q;
q.push({r,c});
while(!q.empty()){
int row = q.front().first;
int col= q.front().second;
q.pop();
for(int i = 0; i < 4; ++i){
int nrow = row + dir[i], ncol = col + dir[i+1];
if(nrow >= 0 && ncol >= 0 && nrow < board.size() && ncol < board[0].size() && board[nrow][ncol] != 'X' && !safe[nrow][ncol]){
safe[nrow][ncol] = true;
q.push({nrow,ncol});
}
}
}
}
public:
void solve(vector& board) {
int m = board.size(), n = board[0].size();
vector safe(m,vector(n,false));
for(int i = 0; i < m; ++i){
for(int j= 0; j < n; ++j){
if(i == 0 || j == 0 || i == m-1 || j == n-1){
if(board[i][j] != 'X' && !safe[i][j]){
bfs(i,j,board,safe);
}
}
}
}
for(int i =0; i < m ; ++i){
for(int j = 0; j < n; ++j){
if(board[i][j] != 'X' && safe[i][j] == true){
continue;
}else{
board[i][j] = 'X';
}
}
}
}
};
Hello, I also tried to solve without watching this video. Can you help me with this code, why it got stuck at 41/58 TC on leetcode :-
class Solution {
public:
void solve(vector& board)
{
int n = board.size();
int m = board[0].size();
vector visited(n, vector (m,0));
vector temp(n, vector (m,'X'));
queue q;
for(int i = 0; i
@@flsh1343 class Solution {
public:
void solve(vector& board) {
int n = board.size();
int m = board[0].size();
vector visited(n, vector (m,0));
vector temp(n, vector (m,'X'));
queue q;
for(int i = 0; i
loving it
Understood Bhaiya
Understood! Is this how to fill by one color in an area surrounded by different color? Anyway, so amazing explanation as always, thank you very much!!
Just Wow observation
thankyou sir 🙇♂❤🙏 understood
understood💙💙💙
thank you bhai💝
Thank you!
Understood thank you sir
Thanks striver
UNDERSTOOD.
thank you bro
Thank you Bhaiya