Word Search | In Depth Explanation | Apple | Amazon | Microsoft | codestorywithMIK

  Рет қаралды 29,562

codestorywithMIK

codestorywithMIK

Күн бұрын

Пікірлер: 97
@vaibhavsrivastava7451
@vaibhavsrivastava7451 2 жыл бұрын
Ahh man you deserve more respect ......thank u so much i always want to hear your voice while understanding leetcode explanation .
@codestorywithMIK
@codestorywithMIK 2 жыл бұрын
Thanks a lot Vaibhav. Really appreciate your kind words. Made my day ❤️❤️❤️ Share it with your friends 😇❤️
@skmdjeesan_
@skmdjeesan_ Ай бұрын
@@codestorywithMIK Hello sir! big fan of your work
@deepakdass4710
@deepakdass4710 7 ай бұрын
I tried to solved it by myself. As I have been following your content from a long time. I have learnt how to approach to solve a problem. I started by drawing recursion tree and then backtracking. Also putting checks to avoid unnecessary conditions. I was able to solve it by myself. And then I watched this video. Thank you Sir 🎉😊
@AbhayGupta-oz1ix
@AbhayGupta-oz1ix 4 ай бұрын
Crystal clear explanation sir. Who will agree that by the end of the video food was ready?
@karnikasingh9140
@karnikasingh9140 7 ай бұрын
Thanks MIK for such for such good explainations!! Here is the java code for same- class Solution { int m; int n; int[][] directions= {{1,0},{-1,0},{0,1},{0,-1}}; public boolean exist(char[][] board, String word) { m = board.length; n = board[0].length; for(int i =0;i
@ToonDubberDuo
@ToonDubberDuo 23 күн бұрын
great
@pragatigoyal4015
@pragatigoyal4015 7 ай бұрын
Your way of explanations is really good, whatever question you explain i dont need to see the code for that i can write my own. Can you make a separate playlist on different approach we use in DSA program and tricks to identify those. It will be easy to follow that playlist if we are having interview
@AnandKumar-kz3ls
@AnandKumar-kz3ls 2 жыл бұрын
Space Complexity: O(L) Time Complexity: O(M * N * 3^L) Space Complexity is because of recursion - to store function stack context. Time Complexity - from every block we go in three adjacent blocks (avoiding the direction we came from). This walk can go for max of L times. So each thred at most goes L length long. -> O(3^L). Now this is applied at each node from main calling function -> O(M * N). Therefore, O(M * N * 3^L).
@codestorywithMIK
@codestorywithMIK 2 жыл бұрын
I’ll ensure to mention TC in the video from next time. Thanks Anand ❤️
@anushkathakur6531
@anushkathakur6531 Жыл бұрын
why are we avoiding the direction we came from? in the sample example if the word was FSA then in 2nd row and 2nd col we would have found F and then we would have 4 options for finding S (left,up,right,down) ??
@bhuppidhamii
@bhuppidhamii 9 ай бұрын
can you explain the SC?
@DevOpskagyaan
@DevOpskagyaan 8 ай бұрын
No one can beat this level of explanation. You deserve more visibility
@gui-codes
@gui-codes 7 ай бұрын
all my doubts are gone. thank you so much.
@souravjoshi2293
@souravjoshi2293 2 жыл бұрын
Hey man, heartful thanks to you. Your soothing voice makes us stick to your video Thanks again for today's code
@killeraloo3247
@killeraloo3247 8 ай бұрын
Bhai mast samjhaya, sab samajh aa gya.
@bhuppidhamii
@bhuppidhamii 9 ай бұрын
Follow up: Could you use search pruning to make your solution faster with a larger board? what does this means?
@qR7pK9sJ2t
@qR7pK9sJ2t 11 ай бұрын
Really very good way of explaining ! Simply awesome !
@codestorywithMIK
@codestorywithMIK 11 ай бұрын
Thanks a lot! 😇❤️🙏
@ananyabhardwaj1861
@ananyabhardwaj1861 5 ай бұрын
please make videos for questions in lover babbar sheet, as I searched through youtube for many questions and I didn't get a good videos like yours .
@tigeryadav-z4t
@tigeryadav-z4t 10 ай бұрын
Brother your way of explanation damn too good you should start teaching dsa and cover all topics from scratch
@codestorywithMIK
@codestorywithMIK 10 ай бұрын
It means a lot to me 🙏🙏❤️❤️ Soon I will start
@EB-ot8uu
@EB-ot8uu 7 ай бұрын
finest explanation
@priyanshugoutam1223
@priyanshugoutam1223 Жыл бұрын
bhaiya aapko concept smjhana aata hai mai dekh chuka ye ....meri aapse request hai if possible please man lena ...aap kisi bhi language me dsa ka course start kardo proper youtube pe hi...i know starting me utne views nahi aate hai but koi bhi dekhega to suggest zrur karega bhaiya please
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Hi Priyanshu. Thanks for your feedback. I will definitely look for this possible Thanks a lot ❤️❤️❤️
@priyanshugoutam1223
@priyanshugoutam1223 Жыл бұрын
@@codestorywithMIK thank you bhaiya
@souravjoshi2293
@souravjoshi2293 Жыл бұрын
Yessss
@pulastyadas3351
@pulastyadas3351 Жыл бұрын
your explanation is like butter :)
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Means a lot. Thank you for watching 😇🙏
@KishoreKumar-rh2tw
@KishoreKumar-rh2tw Жыл бұрын
thanku bhiya,sabse acha aap hi padhate ho.
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Thank you so much Kishore ❤️❤️
@KishoreKumar-rh2tw
@KishoreKumar-rh2tw Жыл бұрын
Bhaiya Nqueen problem pr bhi ek video please,sbka dekhliya nhi smjh aarha
@devshubham5528
@devshubham5528 5 ай бұрын
I am getting TLE with same code on leetcode, what should I do? ( it's exactly same code)
@devshubham5528
@devshubham5528 5 ай бұрын
resolved when I removed loop on directions and manually called the find function
@syedhamzashah3803
@syedhamzashah3803 6 ай бұрын
Which playlist should I follow to get started from the very beginning? Like you didn't explain directions in this video so which one should I refer to?
@abhijitroy1958
@abhijitroy1958 7 ай бұрын
The mark condition in 2nd line of find function I guess lf no use right. Cause we are changing right after the true returns
@suchibansal78
@suchibansal78 Жыл бұрын
very well explained
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Thanks a lot Suchi 😊
@wearevacationuncoverers
@wearevacationuncoverers 7 ай бұрын
masterpiece
@justlc7
@justlc7 5 ай бұрын
Can you please also explain time and space of this?
@ankitsourav1217
@ankitsourav1217 2 жыл бұрын
Bro ek bootcamp lelo, jahan par we can solve good leetcode questions. It will help so much in placements.
@codestorywithMIK
@codestorywithMIK 2 жыл бұрын
Sure Ankit. I have this plan in my queue. Will soon plan it. Thank you so much for your input ❤️❤️❤️
@aws_handles
@aws_handles 7 ай бұрын
too good
@aryangrewal9634
@aryangrewal9634 Ай бұрын
Sir your explaination are very nice , but not look authentic due to bad thumbnail, So apply some change to thumbnail
@codestorywithMIK
@codestorywithMIK Ай бұрын
Appreciate your feedback. I have now made changes in my current videos. Hope that helps ♥️🙏
@sujalgupta6100
@sujalgupta6100 9 ай бұрын
what about the follow up which says to prune ?
@nagmakhan672
@nagmakhan672 2 жыл бұрын
Thanks
@Ash-fo4qs
@Ash-fo4qs Жыл бұрын
video request : leetcode 39,40,216,377
@jagadeeshp1163
@jagadeeshp1163 Жыл бұрын
Respect++ great lecture
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Thank you so much 😇🙏❤️
@jagadeeshp1163
@jagadeeshp1163 Жыл бұрын
can i get a 1-1 session
@codestorywithMIK
@codestorywithMIK Жыл бұрын
@jagadeeshp1163 sure. You can find the link for session in my Github repo - github.com/MAZHARMIK
@jagadeeshp1163
@jagadeeshp1163 Жыл бұрын
HI Mik one doubt when should we write x+solve(....) and when to take x as a parameter like solve(x) how to identify this and i am confused some times we write val+rec() call and sometimes we take val in the rec() call what is the difference please help me out hope you understand my point
@sujansinhthakor2314
@sujansinhthakor2314 7 ай бұрын
Can we solve this problem using BFS?
@devmadaan5146
@devmadaan5146 7 ай бұрын
Leetcode daily 😁, kya haal chal vaise😂
@YashSinghal
@YashSinghal 2 жыл бұрын
wow. what will be the time complexity of the soln??
@codestorywithMIK
@codestorywithMIK 2 жыл бұрын
Hi Yash, The time complexity will be O(m*n*3^L) Where L = length of input word Because in worst case we will visit each cell (m*n) and from each cell our recursion depth will go as far 3^L Why not 4^L Because, we never visit the path where we came from. (If you draw the backtracking/recursion tree, you will notice at any level, 3 Children are allowed since we cannot traverse back to oath from where we came)
@souravjoshi2293
@souravjoshi2293 2 жыл бұрын
O(m*n*3^K), where K = length of word
@vivek.tiwary
@vivek.tiwary Жыл бұрын
What would be time complexity ?
@rudrabhingradiya
@rudrabhingradiya 9 ай бұрын
sir i'm new in your channel and starting video from directly backtracking so i didn't get the topic of direction {1,0},{-1,0}{0,1}{0,-1} so can you tell in which video you had explained it already so i can watch please reply
@codestorywithMIK
@codestorywithMIK 9 ай бұрын
Hey. Actually it's difficult to find the exact video as there are many videos.So let me try to explain and make it simple here : In problems involving depth-first search (DFS) or breadth-first search (BFS), it's common to explore neighboring cells in a grid or graph. The directions array you mentioned is a convenient way to represent the possible movements in terms of changes in the row (i) and column (j) indices. Here's a breakdown : 1) Defining Directions Array: directions = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; This array contains four pairs of numbers, each representing a direction to move in a 2D grid. The pairs are {1, 0} (down), {-1, 0} (up), {0, 1} (right), and {0, -1} (left). 2) Using Directions Array in a Loop: for(auto &dir : directions) { new_i = i + dir[0]; new_j = j + dir[1]; } In this loop, they iterate over each direction represented by the pairs in the directions array. For each direction, they calculate the new row index (new_i) and column index (new_j) by adding the corresponding values from the direction pair to the current indices (i and j). new_i = i + dir[0] calculates the new row index. new_j = j + dir[1] calculates the new column index. By using this loop with the directions array, you can easily explore adjacent cells from a given cell (i, j) without explicitly writing separate code for each direction. This is particularly useful in grid-based problems where you need to traverse neighboring cells during DFS or BFS. Hope this helps.
@DevOpskagyaan
@DevOpskagyaan 8 ай бұрын
@@codestorywithMIKthanks ❤
@kristinabarooah3163
@kristinabarooah3163 7 ай бұрын
which notes app are you using?
@martinnice5255
@martinnice5255 15 күн бұрын
apple notes on ipad
@GauravDuseja-t6q
@GauravDuseja-t6q 7 ай бұрын
Bhaiya when we are writting direction inside find() giving TLE why can someone please help
@devshubham5528
@devshubham5528 5 ай бұрын
remove loop on directions and manually called the find function if( find(board,word,i-1,j,ind+1) ) return true; if( find(board,word,i+1,j,ind+1) ) return true; if( find(board,word,i,j-1,ind+1) ) return true; if( find(board,word,i,j+1,ind+1) ) return true;
@kushaalrana
@kushaalrana 7 ай бұрын
When I write the last if condition in the same if where we are returning false I am getting TLE. Anyone why? This condition in the 2nd if If(board[i][j]!=word[ind]) return false;
@SanjaySingh-xw3mi
@SanjaySingh-xw3mi 7 ай бұрын
Can you please show your whole code then the problem can be identify
@kushaalrana
@kushaalrana 7 ай бұрын
I understood the problem, actually the problem was i didn't not add & in the for loop But what's the difference between For(auto &dir: direction) Vs For(auto dir: direction)
@girikgarg8
@girikgarg8 Жыл бұрын
Nice explanation
@prashantkumarsingh1070
@prashantkumarsingh1070 Ай бұрын
Isn't it dfs ??
@aditigupta6870
@aditigupta6870 6 ай бұрын
Time complexities explanation is missing in all videos
@codestorywithMIK
@codestorywithMIK 6 ай бұрын
Yes in old videos, I missed the discussion of TC and SC. In new videos i add explanation of time and space
@aditigupta6870
@aditigupta6870 6 ай бұрын
Can you explain the time complexity here mik? I mean in this word search problem
@it047_prakhar8
@it047_prakhar8 7 ай бұрын
jo sabse last wali line m return false kia uski need kya thi wo samajh nhi aaya
@acceleratorlevel645
@acceleratorlevel645 7 ай бұрын
It means we have exhausted all possibilities and still haven't seen the word in the matrix, so this means the word doesn't exist,so we return false.
@JainRahul-o2n
@JainRahul-o2n 2 ай бұрын
TLE error ???
@Algorithmswithsubham
@Algorithmswithsubham 7 ай бұрын
sir isme deadlysignal bol raha haiii bool f(int i,int j,int n,int m,string &s,vector& b, string word){ if(i=m)return 0; if(s==word)return 1; s.push_back(b[i][j]); if(f(i+1,j,n,m,s,b,word)==1)return 1; if(f(i-1,j,n,m,s,b,word)==1)return 1; if(f(i,j+1,n,m,s,b,word)==1)return 1; if(f(i,j-1,n,m,s,b,word)==1)return 1; return 0; }
@anshugupta2340
@anshugupta2340 Жыл бұрын
Bro your explanation is damn good!! bro can you help me in finding out whats wrong in the below code. int l,n,m; vectordirections{{0,1},{0,-1},{1,0},{-1,0}}; bool findAll(vector& board, int i,int j,int ind,string&word){ if(ind>=l)return true; if(i=n||j=m||board[i][j]!=word[ind])return false; char temp=board[i][j]; board[i][j]='$'; for(auto &dekh:directions){ int new_i=i+dekh[0]; int new_j=j+dekh[1]; if(findAll(board,new_i,new_j,ind+1,word)); return true; } board[i][j]=temp; return false; } bool isWordExist(vector& board, string word) { n=board.size(); m=board[0].size(); l=word.length(); for(int i=0;i
@gurnoorchhabranit-jalandha5002
@gurnoorchhabranit-jalandha5002 Жыл бұрын
remove semicolon after if conditions
@nish0798
@nish0798 7 ай бұрын
codestorywithMIK bhai ye code mein only 18 test cases hi pass ho rahe hai aisa kya class Solution { public boolean exist(char[][] board, String word) { boolean[][]vis=new boolean[board.length][board[0].length]; String ans=""; char startchar=word.charAt(0); for(int i=0;i
@swagboltey102
@swagboltey102 3 ай бұрын
Directions ka samaj ni aya koi video me explain kiya tha kya
@codestorywithMIK
@codestorywithMIK 3 ай бұрын
The `directions` vector defines the four possible directions you can move from a given cell: right, left, down, and up. Here is a friendly Explanation below with an example - Imagine you have a grid (a 2D matrix) like this: ``` [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] ``` Each cell in the grid can be accessed by its row (`i`) and column (`j`). For example, the cell with value `5` is at position `(1, 1)` (1st row, 1st column). ### Moving Around the Grid The `directions` vector is used to move from one cell to its adjacent cells (right, left, down, up). Here’s what each direction represents: - `{0, 1}`: Move **right** (same row, next column) - `{0, -1}`: Move **left** (same row, previous column) - `{1, 0}`: Move **down** (next row, same column) - `{-1, 0}`: Move **up** (previous row, same column) ### Example of How It Works Let’s say you are currently at cell `(1, 1)` (which is the value `5` in the grid). You want to check all its neighboring cells. Using the code: ```cpp for(auto& dir : directions) { int i_ = i + dir[0]; int j_ = j + dir[1]; // Now (i_, j_) is the position of the neighboring cell } ``` 1. **First iteration** (`dir = {0, 1}`): - `i_ = 1 + 0 = 1` - `j_ = 1 + 1 = 2` - This gives you the cell `(1, 2)` which is `6`. 2. **Second iteration** (`dir = {0, -1}`): - `i_ = 1 + 0 = 1` - `j_ = 1 - 1 = 0` - This gives you the cell `(1, 0)` which is `4`. 3. **Third iteration** (`dir = {1, 0}`): - `i_ = 1 + 1 = 2` - `j_ = 1 + 0 = 1` - This gives you the cell `(2, 1)` which is `8`. 4. **Fourth iteration** (`dir = {-1, 0}`): - `i_ = 1 - 1 = 0` - `j_ = 1 + 0 = 1` - This gives you the cell `(0, 1)` which is `2`. this is typically used to explore all possible paths from a given cell by moving to its neighboring cells. After moving to a neighbor. In case you can also move to diagonal cells, you will have the directions vector like this - vector directions{ {0, 1}, // Move right {0, -1}, // Move left {1, 0}, // Move down {-1, 0}, // Move up {1, 1}, // Move down-right (diagonal) {1, -1}, // Move down-left (diagonal) {-1, 1}, // Move up-right (diagonal) {-1, -1} // Move up-left (diagonal) };
@swagboltey102
@swagboltey102 3 ай бұрын
​@@codestorywithMIKthanks bro agya samjne I'm preparing for Accenture 25th ku exam hai any suggestions for coding round kose questions kare toh kaafi hai
@codestorywithMIK
@codestorywithMIK 3 ай бұрын
@swagboltey102 If it is only coding round, make sure you are well aware of the concepts of important topics like DP, Backtracking , Stack, Heap etc. i have heard that sometimes they ask extremely tough qns. I will suggest you to not waste time in qns which is complex to understand. Quickly move to other qns which you can understand well and solve. The goal is to score as much as possible
@swagboltey102
@swagboltey102 3 ай бұрын
@@codestorywithMIK ha par me arrays aur string me perfect ni hu isliye abhi move ni Kiya
@molyoxide8358
@molyoxide8358 Жыл бұрын
Bro pls check this code. It's not working class Solution { public: int m=0,n=0; bool backtrack(vector& board, string &word, int i, int j, int idx) { if(idx == word.size()) return true; if(i>=m || j>=n || i
@AJ-xc3ks
@AJ-xc3ks 11 ай бұрын
Bro u are calling for all the char of board Firstly check that 1st char of word and board ele match then call
@molyoxide8358
@molyoxide8358 11 ай бұрын
@@AJ-xc3ks Didn't understand It's been 5 months since this problem can you pls point it out.
@ssplusultra8645
@ssplusultra8645 7 ай бұрын
if anyone is wondering, leetcode pro'lly updated the test cases and this implementation gives TLE now. we can do something like this instead of using directions and for loop: ``` bool searchWord(vector& board, int i, int j, int k, string &word){ if(k==word.size()) return true; if(i=m|| board[i][j]=='$'){ return false; } if(board[i][j]!=word[k]) return false; char temp = board[i][j]; board[i][j] = '$'; bool ret = searchWord(board, i-1, j, k+1, word) || searchWord(board, i+1, j, k+1, word) || searchWord(board, i, j-1, k+1, word) || searchWord(board, i, j+1, k+1, word); board[i][j] = temp; return ret; } ```
@abhinav7622
@abhinav7622 7 ай бұрын
thanks bro !!!
@vinayjoshi8714
@vinayjoshi8714 3 ай бұрын
correct bro 👍
@aditigupta6870
@aditigupta6870 8 ай бұрын
Hi sir, whats wrong here? It fails 13 test cases including 1 example test case with word SEE: class Solution { int m,n; int[] dx={-1,1,0,0}; int[] dy={0,0,-1,1}; int i_,j_,k; public boolean isPresent(char[][] board,int i,int j,String word,int ind){ if(ind==word.length())return true; if(i
@kashifrahman
@kashifrahman Жыл бұрын
I can't understand the direction vector 🥲
@kamranwarsi12b22
@kamranwarsi12b22 Жыл бұрын
class Solution { public: bool solve(int i, int j, int n, int m, vector& board, string &word, int k){ if(k==word.size()){ return true; } if(i=m || board[i][j]!=word[k]){ return false; } char ch = board[i][j]; board[i][j] = '#'; bool op1 = solve(i+1,j,n,m,board,word,k+1); //down bool op2 = solve(i-1,j,n,m,board,word,k+1); //up bool op3 = solve(i,j+1,n,m,board,word,k+1); //right bool op4 = solve(i,j-1,n,m,board,word,k+1); //left board[i][j] = ch; return op1||op2||op3||op4; } bool exist(vector& board, string word){ int n = board.size(); int m = board[0].size(); for(int i=0; i
小路飞还不知道他把路飞给擦没有了 #路飞#海贼王
00:32
路飞与唐舞桐
Рет қаралды 87 МЛН
FOREVER BUNNY
00:14
Natan por Aí
Рет қаралды 25 МЛН
How Much Tape To Stop A Lamborghini?
00:15
MrBeast
Рет қаралды 211 МЛН