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.
Using same given function and not creating a separate method (I didn't feel the need) public int[][] floodFill(int[][] image, int sr, int sc, int color) { // find neighbours and add to stack int val = image[sr][sc]; int left = sc-1 >= 0 ? image[sr][sc-1] : -1; int right = sc+1 = 0 ? image[sr-1][sc] : -1; int down = sr+1
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
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.
You have the ultimate power to make us understand complex problems very easily that's what makes you powerful. Your the best...
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.
your mistake was a good thing to learn from
The most blessed thing is that I am stuck with a question, but Nick has already solved it and made a video.
this line saved my day thanks! I was going with stackOverFlow exception without it.
if ( image[sr][sc] == newColor ) return image;
1:21 number of islands, flood fill, rotten oranges.....etc basically bfs n dfs algos
You were right, this is almost identical to number of islands. Once I got this I figured that one out pretty quickly.
Thanks a lot for the clear explanation. Just keep doing this awesome work. It really means a lot to me.
Using same given function and not creating a separate method (I didn't feel the need)
public int[][] floodFill(int[][] image, int sr, int sc, int color) {
// find neighbours and add to stack
int val = image[sr][sc];
int left = sc-1 >= 0 ? image[sr][sc-1] : -1;
int right = sc+1 = 0 ? image[sr-1][sc] : -1;
int down = sr+1
Thank You So for this wonderful video.........🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻
The first line is essential; otherwise, the recursion function call will go into an infinite loop.
What is the time and space complexity? I'm guessing time = O(n) and space = O(1). Is that right?
So there are 732 other episodes of this series?
it's kinda funny how Nick is always High :D
Keep doing that awesome work man! Got it instantly, your explanations are very clear.
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.
image[sr][sc]==newColor, condition has to be added under if condition of void fill?
hello Sir
i am getting stuck at the below test case
[[0,0,0],[1,0,0]]
1
0
2
Will this work if the starting point is [0][0] ??
just 850 problems away to complete all leet code problems😀😀
R u doing ur UG now ?
1692 more to go for me !
we optimize this by not visiting nodes again which are already visited right?
@Richa won't that part get handled in the condition img[sr][sc] !=color ?
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
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.
Your videos are really helpful man ! Thanks a ton
Thanks so much
Also the last mistake i didn't know about it, thanks man
Can anyone explain why sc >= image[0].length and not sc >= image.length ?
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.
Good explanation!
Thanks purge
this is so cool!
Thanks
you are just awesome
how do i get 100% faster than everyone else
If the new color is the same as the old color, wouldn't that make an infinite recursion
No, that's caught by line 3. It never even gets to the recursive function. "if (image[sr][sc] == newColor) return image;"
Hey the discord link is invalid, can someone send me the link, or comment it
When Asians watching your videos, you know how good you are
GOAT
Decent!
4:21 boi
python problém
👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏