Word Search | LeetCode 79 | C++, Java, Python3

  Рет қаралды 30,988

Knowledge Center

Knowledge Center

Күн бұрын

Пікірлер: 46
@sushantmishra6589
@sushantmishra6589 3 жыл бұрын
Time complexity is not O(V) where V is no of vertices (i.e M*N), but time complexity is O(V*4^S) where S is string length. As we are going down the dfs tree we are calling 4 dfs calls every time and we are calling it for S times so one complete dfs will have time complexity of 4^S, and as we are traversing the graph every vertices could match first letter of word, so we will be calling V dfs calls. So its O(V*4^S)
@yashaggarwal6760
@yashaggarwal6760 2 жыл бұрын
Best video i have seen on this problem for c++, Kudos to you!!!
@KnowledgeCenter
@KnowledgeCenter 2 жыл бұрын
Thanks.
@jaggyjack1005
@jaggyjack1005 2 жыл бұрын
Leetcode not accepting solution with extra space (TLE)
@singiri697
@singiri697 2 жыл бұрын
Vector visited(r, vector(c, false)); means we are making initially all cells of the board size as false? Please answer my doubt
@KnowledgeCenter
@KnowledgeCenter 2 жыл бұрын
Yes.
@singiri697
@singiri697 2 жыл бұрын
@@KnowledgeCenter why dovwe return true if idx == word.length()?
@samarthpatel7260
@samarthpatel7260 4 жыл бұрын
What should I use in Java instead of 2d vector in C++ for this two lines of your 1st solution: vector visited(r, vector(c,false)); Thank you!
@KnowledgeCenter
@KnowledgeCenter 4 жыл бұрын
boolean visited[][] = new boolean[r][c];
@siddharthsingh4330
@siddharthsingh4330 4 жыл бұрын
Any good book to practice DS and Algo in python?
@codeculture2
@codeculture2 3 жыл бұрын
best explanation, thanks and keep uploading!
@KnowledgeCenter
@KnowledgeCenter 3 жыл бұрын
Thanks.
@pratyushranjansahu9495
@pratyushranjansahu9495 4 жыл бұрын
The only difference between Word Search II and this problem is that..There we have list of words thats why we were using Trie . Here only one word so. it can be solved like simple DFS. This problem can also be solved by Trie approach but Word Search II can't be solved by this approach ? Correct me if i am wrong..
@PL___
@PL___ 4 жыл бұрын
If we use temp = board[i][j] to store current char before dfs all adjacent cells, and board[I][j] = temp, would this still counts as O(1) space ?
@KnowledgeCenter
@KnowledgeCenter 4 жыл бұрын
It can go up to O(word size).
@narendranamdev7135
@narendranamdev7135 3 жыл бұрын
Litraaly helpful...you are awesome!!
@KnowledgeCenter
@KnowledgeCenter 3 жыл бұрын
Thanks.
@sanjeevkumar-wm4mn
@sanjeevkumar-wm4mn 4 жыл бұрын
Hi , You said there is a video on dfs . can you please post the link for the same in description
@KnowledgeCenter
@KnowledgeCenter 4 жыл бұрын
Check this playlist: kzbin.info/aero/PL1w8k37X_6L9IfRTVvL-tKnrZ_F-8HJQt
@rinakadam4662
@rinakadam4662 Жыл бұрын
Thanks for the video ... Really helpful :)
@ayulj
@ayulj 4 жыл бұрын
How is this O(4*n), every path triggers another possibility, should it not be O(n*word size)? I am really confused about it's time complexity
@PL___
@PL___ 4 жыл бұрын
You are right, we assumed that word size is smaller than n. I don't think O(n*word size) is wrong.
@KnowledgeCenter
@KnowledgeCenter 4 жыл бұрын
Agreed.
@ghanshyampatel2749
@ghanshyampatel2749 4 жыл бұрын
thank you sir!! it's helped me a lot!
@KnowledgeCenter
@KnowledgeCenter 4 жыл бұрын
Glad it helped!
@rahls7
@rahls7 3 жыл бұрын
probably a good idea to have a separate video for every language.
@pratyushranjansahu9495
@pratyushranjansahu9495 4 жыл бұрын
Hi, Video is not available. can you plz check it out
@KnowledgeCenter
@KnowledgeCenter 4 жыл бұрын
Now check.
@pratyushranjansahu9495
@pratyushranjansahu9495 4 жыл бұрын
@@KnowledgeCenter Ya working...now
@akshatmehta4271
@akshatmehta4271 4 жыл бұрын
how do you arrive at the approach so easily ???
@KnowledgeCenter
@KnowledgeCenter 4 жыл бұрын
For questions like this at least I can say that, if you ask somebody how to search a word here, that person would start looking for First letter of word in the grid, then look at top/bottom/left/right of that cell, and if 2nd character matches, look for 3rd character in neighbourhood and so on. Exact same logic is used in the solution here. DFS is a very natural way of exploring things. Like a Rat in a maze doesn't know DFS, but uses something similar to come out of maze. So, first think of solution non-programmatically, then think which data structure to use for implementing that solution/algorithm. Also a lot depends on practice.
@igorlevdansky4545
@igorlevdansky4545 4 жыл бұрын
Please, do not forget to add default english subtitles .
@AlokKumar-jh8wp
@AlokKumar-jh8wp 4 жыл бұрын
sir want to know how you solve these problems so efficiently. I am still not able to understand how to approach these problems
@KnowledgeCenter
@KnowledgeCenter 4 жыл бұрын
For questions like this at least I can say that, if you ask somebody how to search a word here, that person would start looking for First letter of word in the grid, then look at top/bottom/left/right of that cell, and if 2nd character matches, look for 3rd character in neighbourhood and so on. Exact same logic is used in the solution here. DFS is a very natural way of exploring things. Like a Rat in a maze doesn't know DFS, but uses something similar to come out of maze. So, first think of solution non-programmatically, then think which data structure to use for implementing that solution/algorithm. Also a lot depends on practice.
@AlokKumar-jh8wp
@AlokKumar-jh8wp 4 жыл бұрын
Knowledge Center thankyou sir you are awsome
@pratimdas8703
@pratimdas8703 2 жыл бұрын
Really helped
@crankyinmv
@crankyinmv 4 жыл бұрын
Thanks for the video as always. I did something very similar to the non-space-optimized solution. The biggest difference being that I used an oversized visited array (large enough to have a 1 element frame over the board) which allowed me to eliminate the bounds checking. I got 91% (admittedly there's a large random element in JS run times). I was real proud of myself until some sadist in the discussion pointed out that most of these solutions would time out on something like 'c' (times 998) 'b' (on a 100x100 board of all 'c's). I was hoping you had some DP magic which could handle that.
@mohammadarsalan9035
@mohammadarsalan9035 4 жыл бұрын
hiii great explaination but can you tell me what does vector visited(r, vector(c,false)); in your code?? Thankx in advance
@KnowledgeCenter
@KnowledgeCenter 4 жыл бұрын
vector visited(r, vector(c,false)); visited is a 2D vector of size r x c, each initialized to false.
@floatingpoint7629
@floatingpoint7629 4 жыл бұрын
This problem is very similar to number of islands
@devalmodi5350
@devalmodi5350 4 жыл бұрын
Not able to see the video
@KnowledgeCenter
@KnowledgeCenter 4 жыл бұрын
Check now.
@devalmodi5350
@devalmodi5350 4 жыл бұрын
@@KnowledgeCenter Working now!!
@bhargavimopuru8576
@bhargavimopuru8576 2 жыл бұрын
already word is given how to find their indexes inputs are after 4 a b c d f e f g t e r r a b i j output wants to come as [(0,0),(1,0),(2,0),(2,1),(2,2)] different inputs are search 4 s e a c r c c c h e e e h e e e output wants to come as "no such word is there" how will do this in python pls explain
@amitsharma5551
@amitsharma5551 2 жыл бұрын
This is wrong for input [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"] & word=ABCB
Word Search ii | LeetCode 212 | C++, Java, Python
35:05
Knowledge Center
Рет қаралды 8 М.
Word Search - Leetcode 79 - Recursive Backtracking (Python)
12:24
We Attempted The Impossible 😱
00:54
Topper Guild
Рет қаралды 55 МЛН
UFC 310 : Рахмонов VS Мачадо Гэрри
05:00
Setanta Sports UFC
Рет қаралды 1,2 МЛН
Reverse Nodes in k-Group | LeetCode 25 | C++ 🕵️‍♂️🔥
27:35
Knowledge Center
Рет қаралды 13 М.
Word Search - Backtracking - Leetcode 79 - Python
10:18
NeetCode
Рет қаралды 344 М.
3Sum | LeetCode 15 | C++, Java, Python
22:24
Knowledge Center
Рет қаралды 38 М.
I gave 127 interviews. Top 5 Algorithms they asked me.
8:36
Sahil & Sarra
Рет қаралды 679 М.
[Java] Leetcode 79. Word Search [Backtracking #11]
16:39
Eric Programming
Рет қаралды 2,4 М.
Word Search
8:46
Kevin Naughton Jr.
Рет қаралды 139 М.
We Attempted The Impossible 😱
00:54
Topper Guild
Рет қаралды 55 МЛН