LeetCode Word Search Solution Explained - Java

  Рет қаралды 45,428

Nick White

Nick White

5 жыл бұрын

The Best Place To Learn Anything Coding Related - bit.ly/3MFZLIZ
Join my free exclusive community built to empower programmers! - www.skool.com/software-develo...
Preparing For Your Coding Interviews? Use These Resources
--------------------
(My Course) Data Structures & Algorithms for Coding Interviews - thedailybyte.dev/courses/nick
AlgoCademy - algocademy.com/?referral=nick...
Daily Coding Interview Questions - bit.ly/3xw1Sqz
10% Off Of The Best Web Hosting! - hostinger.com/nickwhite
Follow My Twitter - / nicholaswwhite
Follow My Instagram - / nickwwhite
Other Social Media
----------------------------------------------
Discord - / discord
Twitch - / nickwhitettv
TikTok - / nickwhitetiktok
LinkedIn - / nicholas-w-white
Show Support
------------------------------------------------------------------------------
Patreon - / nick_white
PayPal - paypal.me/nickwwhite?locale.x...
Become A Member - / @nickwhite
#coding #programming #softwareengineering

Пікірлер: 37
@luisgualpa7019
@luisgualpa7019 3 жыл бұрын
The most relatable programmer lol, thanks for making these videos man
@jingli2168
@jingli2168 4 жыл бұрын
It seems that you are not fully understand this problem and just recite the CODE!
@theoDSP
@theoDSP Жыл бұрын
My thoughts exactly
@jlecampana
@jlecampana 4 жыл бұрын
You fail to explain a very important part of this problem, that is *Why it's not the same as Number of Islands*, and the reason is that you backtrack in line 41: visited[i][j] = false; That part should be carefully explained.
@dmitrykarpenko2271
@dmitrykarpenko2271 3 жыл бұрын
Just to have the explanation here: Visited array here marks the currently examinad word so we don't try to use its letter twice (e.g. don't intersect it).
@AvinashS273
@AvinashS273 3 жыл бұрын
watch this
@vulturebeast
@vulturebeast 3 жыл бұрын
It's kind of like when we do dfs with that word, we should not consider in the so called dfs graph all the visited words so we mark them as true, but after dfs call gets over.. (all our recursive calls) then we can mark it as false as they're no longer in dfs graph we've needing.
@danrussell_official
@danrussell_official 4 жыл бұрын
Thanks nick! I just encountered the exact same problem with the “aaa” test case. Unlike you I tried to make a node graph with edges but now that I see your solution i see that I was trying too hard lol. Super helpful thanks man
@Edmundlu
@Edmundlu 2 жыл бұрын
loving the debugging part at the end!
@yoojinlee9125
@yoojinlee9125 Жыл бұрын
Thank you, this is so helpful! I love how you explain the thought process
@yuewu3888
@yuewu3888 3 жыл бұрын
Thank you Nick, this is very helpful.
@nikhilnaidu1383
@nikhilnaidu1383 3 жыл бұрын
why not index==word.length()-1
@mohanmanu8605
@mohanmanu8605 4 жыл бұрын
stuck at exactly same place and then i watched this video
@fairozahmed6888
@fairozahmed6888 5 жыл бұрын
Awesome Nick
@JOBFERNANDEZBCD
@JOBFERNANDEZBCD Жыл бұрын
thanks a lot. was stuck at this problem.
@linhnguyenduc641
@linhnguyenduc641 Жыл бұрын
Thank Nick, I like your idea to create a visited boolean array. Besides, you speed up the algorithm by searching only when the first character in word matches current position in board. ❤
@ProgrammingP123
@ProgrammingP123 10 ай бұрын
This was required tho, not an optimization. You can't use the same letter twice
@luciay742
@luciay742 2 жыл бұрын
Thank you so much, it is very helpful!
@charlesbickham6604
@charlesbickham6604 4 жыл бұрын
Can someone please explain to me how that if statement that calls recursively works? I understand how it is called but it does not connect how it will return true for me. Thank you.
@ydenda8471
@ydenda8471 4 жыл бұрын
the main recursive statement calls itself over and over again until a base case is reached for each individual recursive call then returns those values. Basically opening a box with many other boxes inside of it until the last box with the prize is opened.
@shreyrawat7108
@shreyrawat7108 11 ай бұрын
hey nick i hope you keep doing what you do.
@azharuddinkhan1865
@azharuddinkhan1865 Жыл бұрын
Very nice solution
@rohit-ld6fc
@rohit-ld6fc 4 жыл бұрын
Why do we make the visited[i][j] = false again ?
@TinTin-vx4nh
@TinTin-vx4nh 4 жыл бұрын
it's because we need to refresh board and set up visited[I][j] = false in order to check whether other possibilities are true or false.
@mevam123
@mevam123 4 жыл бұрын
This is the most important part of this question. With the help of visited array we are backtracking, we assigned it false because if none of the paths worked out we need to re search the grid starting from afresh.
@audaciouspert1772
@audaciouspert1772 2 жыл бұрын
@@mevam123 Thanks for the best explanation out there. Much helpful
@vishwanathpatil2995
@vishwanathpatil2995 4 жыл бұрын
you can just flag the visited element instead of maintaining one more array.
@chrisw4889
@chrisw4889 4 жыл бұрын
how to flag it
@justanaverageguy4739
@justanaverageguy4739 4 жыл бұрын
there may be more than one word[0] in board,but we can't pass the same flaged matrix again for another word[0] so there is no way . we need to copy the whole visited matrix again
@pankajrathi
@pankajrathi 4 жыл бұрын
@@chrisw4889 You can just store it in a temp variable then set the board[i][j] values to empty literal and at the end set back board[i][j] back to temp.
@ravijain8732
@ravijain8732 3 жыл бұрын
How is this similar to number of islands? The initial for loop is, I suppose, but the algorithm used is completely different. Islands used DFS and this is backtracking
@Sportsandgames6
@Sportsandgames6 5 ай бұрын
Technically similar, DFS is based on this type of recursion
@TotSamyiAltynAdam_17
@TotSamyiAltynAdam_17 Жыл бұрын
Thanks ❤‍🔥
@raj_kundalia
@raj_kundalia 9 ай бұрын
thanks!
@AmandeepSingh-kp5wp
@AmandeepSingh-kp5wp 2 жыл бұрын
honest vid
@Fresh-sh2gc
@Fresh-sh2gc Жыл бұрын
your explanation is not very good my guy.
@starightupdeath69
@starightupdeath69 3 ай бұрын
and then comes the tle
LeetCode Search A 2D Matrix Solution Explained - Java
11:47
Nick White
Рет қаралды 38 М.
Word Search - Leetcode 79 - Recursive Backtracking (Python)
12:24
когда повзрослела // EVA mash
00:40
EVA mash
Рет қаралды 3,9 МЛН
Always be more smart #shorts
00:32
Jin and Hattie
Рет қаралды 46 МЛН
HOW DID HE WIN? 😱
00:33
Topper Guild
Рет қаралды 27 МЛН
I Got Rejected (again)
9:43
Nick White
Рет қаралды 202 М.
Word Search
8:46
Kevin Naughton Jr.
Рет қаралды 139 М.
Binary Search Algorithm - Computerphile
18:34
Computerphile
Рет қаралды 157 М.
8 patterns to solve 80% Leetcode problems
7:30
Sahil & Sarra
Рет қаралды 225 М.
LeetCode Spiral Matrix Solution Explained - Java
11:07
Nick White
Рет қаралды 47 М.
WORD SEARCH | LEETCODE 79 | PYTHON DFS SOLUTION
18:54
Cracking FAANG
Рет қаралды 3,1 М.
I gave 127 interviews. Top 5 Algorithms they asked me.
8:36
Sahil & Sarra
Рет қаралды 613 М.
LeetCode Remove K Digits Solution Explained - Java
11:06
Nick White
Рет қаралды 21 М.
Собери ПК и Получи 10,000₽
1:00
build monsters
Рет қаралды 2,2 МЛН
Спутниковый телефон #обзор #товары
0:35
Product show
Рет қаралды 2,1 МЛН
Мой инст: denkiselef. Как забрать телефон через экран.
0:54