LeetCode 733. Flood Fill (Algorithm Explained)

  Рет қаралды 54,944

Nick White

Nick White

4 жыл бұрын

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

Пікірлер: 46
@biswamohandwari6460
@biswamohandwari6460 4 жыл бұрын
You have the ultimate power to make us understand complex problems very easily that's what makes you powerful. Your the best...
@TheBsoncarty
@TheBsoncarty Жыл бұрын
Idk if you read these comments anymore, but I want to say thanks dude. These videos that you've made have been vital to my ability to understand how to approach LeetCode questions.
@tushargupta2356
@tushargupta2356 4 жыл бұрын
your mistake was a good thing to learn from
@thommy270
@thommy270 2 жыл бұрын
Keep doing that awesome work man! Got it instantly, your explanations are very clear.
@kishoureb6833
@kishoureb6833 3 жыл бұрын
Thanks a lot for the clear explanation. Just keep doing this awesome work. It really means a lot to me.
@ahmadalk2540
@ahmadalk2540 3 жыл бұрын
this line saved my day thanks! I was going with stackOverFlow exception without it. if ( image[sr][sc] == newColor ) return image;
@ruibinzhang
@ruibinzhang 10 ай бұрын
The most blessed thing is that I am stuck with a question, but Nick has already solved it and made a video.
@harinijeyaraman8789
@harinijeyaraman8789 4 жыл бұрын
Your videos are really helpful man ! Thanks a ton
@vyshnavramesh9305
@vyshnavramesh9305 4 жыл бұрын
1:21 number of islands, flood fill, rotten oranges.....etc basically bfs n dfs algos
@adityap613
@adityap613 Жыл бұрын
You were right, this is almost identical to number of islands. Once I got this I figured that one out pretty quickly.
@rohanbasavaraju
@rohanbasavaraju 4 жыл бұрын
Awesome video! How can you initially tell this is a DFS problem and not BFS? Additionally, do you have any useful tips for identifying if a problem will use DFS or BFS?
@amrholo4445
@amrholo4445 2 жыл бұрын
Thanks so much Also the last mistake i didn't know about it, thanks man
@expansivegymnast1020
@expansivegymnast1020 Жыл бұрын
Good explanation!
@stith_pragya
@stith_pragya 7 ай бұрын
Thank You So for this wonderful video.........🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻
@smellthel
@smellthel 3 жыл бұрын
So there are 732 other episodes of this series?
@jacksingermusic
@jacksingermusic Жыл бұрын
What is the time and space complexity? I'm guessing time = O(n) and space = O(1). Is that right?
@RagingAcid
@RagingAcid 11 ай бұрын
Thanks purge
@janneskleinau6332
@janneskleinau6332 9 ай бұрын
this is so cool!
@eliastouil7686
@eliastouil7686 Ай бұрын
Thanks
@theonly1me
@theonly1me 2 жыл бұрын
it's kinda funny how Nick is always High :D
@ruibinzhang
@ruibinzhang 10 ай бұрын
The first line is essential; otherwise, the recursion function call will go into an infinite loop.
@ZEE-fs6hv
@ZEE-fs6hv 4 жыл бұрын
just 850 problems away to complete all leet code problems😀😀
@vishalcelestine8654
@vishalcelestine8654 4 жыл бұрын
R u doing ur UG now ?
@mashak3765
@mashak3765 3 жыл бұрын
1692 more to go for me !
@mohammedharoon1167
@mohammedharoon1167 Ай бұрын
you are just awesome
@sanskargupta7800
@sanskargupta7800 2 жыл бұрын
hello Sir i am getting stuck at the below test case [[0,0,0],[1,0,0]] 1 0 2
@richa6695
@richa6695 4 жыл бұрын
we optimize this by not visiting nodes again which are already visited right?
@dileshsolanki2383
@dileshsolanki2383 3 жыл бұрын
@Richa won't that part get handled in the condition img[sr][sc] !=color ?
@zn4798
@zn4798 4 жыл бұрын
just very curious why you need to write another function, is it possible that return it in the same function? I mean use the recursive for the function floodfill
@sfitz219
@sfitz219 3 жыл бұрын
You could put the old color in a variable at the beginning of the function, and put each of the recursive calls in an if statement, which checks if that index would be out of bounds, and if that pixel is the same color. That was what I tried first, it worked on small images on my computer, it only passed the first 16 test cases on leetcode website before getting a stack overflow on the 17th. When I added a check at the beginning that returns the unmodified image if the oldColor == newColor, it started working. I guess one of the test cases is a huge image where the pixel they try starting the flood fill at is already the color they're filling it with.
@prathyushakadali3330
@prathyushakadali3330 Ай бұрын
Thanks so much for sharing this, but doesn't this cause repetition? for eg: void fill method is called for sr=1, sc=1, more than it is required.
@prathyushakadali3330
@prathyushakadali3330 Ай бұрын
image[sr][sc]==newColor, condition has to be added under if condition of void fill?
@jaideeph6985
@jaideeph6985 Жыл бұрын
Will this work if the starting point is [0][0] ??
@sanatgawade8045
@sanatgawade8045 2 жыл бұрын
Can anyone explain why sc >= image[0].length and not sc >= image.length ?
@jesusjurado222
@jesusjurado222 2 жыл бұрын
The image will not always be square, so sr is limited to the length of the encompassing array, and sc will be limited to the length the nested array.
@rhinoara7119
@rhinoara7119 2 жыл бұрын
When Asians watching your videos, you know how good you are
@DaBestn00b
@DaBestn00b 4 жыл бұрын
how do i get 100% faster than everyone else
@AnandBaburajan
@AnandBaburajan 3 жыл бұрын
4:21 boi
@MsFerid567
@MsFerid567 2 жыл бұрын
GOAT
@drewanderson5867
@drewanderson5867 3 жыл бұрын
Hey the discord link is invalid, can someone send me the link, or comment it
@MrRaminfar
@MrRaminfar 2 жыл бұрын
If the new color is the same as the old color, wouldn't that make an infinite recursion
@alexwilkinson3460
@alexwilkinson3460 2 жыл бұрын
No, that's caught by line 3. It never even gets to the recursive function. "if (image[sr][sc] == newColor) return image;"
@davidrowlands8548
@davidrowlands8548 Жыл бұрын
Decent!
@dannyhd8301
@dannyhd8301 Жыл бұрын
👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏
@radwaneberredai6622
@radwaneberredai6622 4 жыл бұрын
python problém
Self Taught Programmers... Listen Up.
11:21
Nick White
Рет қаралды 1 МЛН
How does flood fill work?
8:10
Leios Labs
Рет қаралды 26 М.
Каха ограбил банк
01:00
К-Media
Рет қаралды 11 МЛН
Became invisible for one day!  #funny #wednesday #memes
00:25
Watch Me
Рет қаралды 51 МЛН
Получилось у Вики?😂 #хабибка
00:14
ХАБИБ
Рет қаралды 7 МЛН
Dynamic Programming / Flood Fill Algorithm
5:45
Michael Backus
Рет қаралды 92 М.
Flood Fill | Leetcode #733
10:32
Techdose
Рет қаралды 52 М.
This is how Paint's bucket fill works (Flood fill algorithm)
8:54
LeetCode 146. LRU Cache (Algorithm Explained)
18:00
Nick White
Рет қаралды 115 М.
I gave 127 interviews. Top 5 Algorithms they asked me.
8:36
Sahil & Sarra
Рет қаралды 613 М.
Number of Islands - Leetcode 200 - Graphs (Python)
11:01
Greg Hogg
Рет қаралды 2,3 М.
Leetcode - The Path to Enlightenment
3:11
NeetCodeIO
Рет қаралды 147 М.
Big O Notation, Time Complexity | DSA
21:17
Telusko
Рет қаралды 55 М.
Leetcode - Flood Fill (Python)
7:01
Timothy H Chang
Рет қаралды 7 М.
В России ускорили интернет в 1000 раз
0:18
Короче, новости
Рет қаралды 1,8 МЛН
Мечта студента - диктофон с ChatGPT
1:00