Hey Nick, I watched all of your LeetCoding videos to help me prepare for my technical interviews. I was able to secure two offers from big tech companies (including a FAANG). I just wanted to thank you for making these videos and helping people like myself achieve their professional goals!
This guy rocks! I love his videos and explanations. I’ve been in the programming space for 21.5 years but I don’t get bored of listening to Nick White. He’s intelligent, enthusiastic, innovative and has excellent problem solving skills. This is the guy I’d like in my team.
Hey Nick! Many students from India just like me watch your channel and learn logics with very easily readable code. I just want to tell you that you are doing a great job and please keep the videos coming Everybody enjoys your video not just because you solve the problem but because you solve them with a lot of ease and fun.
When you were winding down with the wrap-up, that's usually when I close the videos and I didn't really appreciate the algorithm, but I was so happy to have it running in the background as you revisited it and then demonstrated why it works and that just cleared all the fog and it suddenly made perfect sense.
I like this Nick White's explanation. He is precise simple and short. He is not boring explanation like others who takes 30min explanation on every small topics. When you are on the flow and need some hints. You wouldn't like to listen to 30-40 min boring explanation.
But the irony is interviewer expect in 25 minutes with production ready code. So if you don't know algorithm in advance then very difficult to crack and if you know then anyone can solve in 10 minutes.
Your videos are the best! I’m preparing for a job switch and learning ds & algorithms, nobody explains the things like you do. Thank you so much for helping us out! Keep doing the good work!
NIT - Magic at 12:58. Line#6 , cur became current_sum on click run tests. Just for fun (or i did not understand your sarcasm). Your videos rock. Going back and explaining how we lost -2 and started over with 2 is amazing.
I was on the fence about giving that like he asked for, but the little plug in 5:38 cemented it, liked from me, all day everyday, fuck yea for Nick White.
I spent 7 hours (whole night) reading the textbook and watching RUclips trying to understand this. Was about to give up my college until i saw this video.
One "preprocessing step" would be to throw away any leading and trailing negative numbers in the array since they cannot help, then apply Kadane's algorithm to whatever is left. So the solution to [-2, 2, 5, -11, 6] is the same as the solution to [2, 5, -11, 6] which is the same as the solution to [-4, -3, -2, 2, 5, -11, 6, -1, -99]
Hope that helps more to understand just added comment to the code to dry track.!! int [] array= {-2,2,5,-11,6}; int max_sum=array[0]; //i.e -2 int current_sum=max_sum; //i.e -2 for(int i=1;i
Damn. I was going though Priority Queues similar to a Huffman encoding tree combing Max Sum pairs into new nodes and leafs, but your solution was much easier. Nice work!
If you ever find it hard to understand the implementation, just know that current_sum stores the sums of the Contiguous sub array. And if the sum is every less that the next element in the array, then it starts a new count.
Can we also solve it through recursion? Essentially breaking down arrays into two parts and returning max among them. Base case would be array size 1. 1) Array including first index and excluding last index 2) Array excluding first index and including last index
There is slight Correction in this code! Initialize: max_so_far = 0 max_ending_here = 0 Loop for each element of the array max_ending_here = max_ending_here + a[i] if(max_ending_here < 0) max_ending_here = 0 if(max_so_far < max_ending_here) max_so_far = max_ending_here return max_so_far
If we run two loops, one for the first and one for the last number, and then we sum. So we start to compare which one is greater if we offset the first or the last (closing in). Edit: I'm new to coding, I just came here to see which problems are expected to be solved.
Solution method/function is off. Try input array = {-2,2,5,-11,8,6,-7,10}. At 7th iterating;- current_sum = max(current_sum + arr[7], arr[7]). the result is current_sum + 10 = 14 + 10 = 24. Result should be 14
Hi Nick, i have a short Question: Is the Steem Account "iwudah" belongs to you and do you have recently published this Video here on the Steem Platform? Thanks in Advance - greetings, louis
I hope your channel gets more popular, this is top quality content. Also just a thing i noticed, the statement with x = max(a, a+b) is way cleaner and shorter than what I would typically write like an if and else statement 👍
I like the explanation at all, but there is a slight logic improvement that can be made in line 5. Notice that we check for the greatest of nums[i] and nums[i]+ current_sum. It is the same as comparing nums[i] + 0 and nums[I] + current_sum. Substracting nums[i] from both sides gives us comparing 0 and current_sum. And our current_sum then must look like Max(0, current_sum) + nums[i]. Not that much of work, but looks a bit more perfect as for me. Still great video as always ❤
Thanks for this video! Is knowing bruteforce and Kane's aglo enough for this problem? Would interviewers usually ask to solve this in different approach like divide and conquer?
Sir can you make a video on how to calculate time and space complexity . Like i have seen many videos but still. For ex- take 1 example of all sorting techniques and tell us how to find time complexity and you can even modify the sorting technique and show us the new complexity....it will be of great help sir🥺
Love it! I found gold when I found your channel! Tried with several cases, with the methods you taught, how can we return the index of the subarray as well?
You could try keeping two pointers m and n for returning the indices of the subarray. We would update both m and n whenever we find a cur_sum that beats our max_sum and starts a new subarray sum (i.e current element > cur_sum). We would update only n if our cur_sum beats out our max_sum and we don't start a new subarray sum.
Hi there, thanks for the video, but when I submit the code following the ideas, the leetcode gives me a special case, when length of the array = 1, for example, then the output will be 2, so better get the length checked before the loop.
The space complexity of this algorithm is O(2) since there are only two integers that are stored, regardless of the input. Usually we remove the coefficients of Big O Notation, so if we do that to this the space complexity is O(1) [constant space]
Samsung: "Try to find the maximum sub-arr-"
Me after watching Nick White: "Yo, you're coming at me with this weak crap?"
Hahahaha. I laughed long after reading this. :D
lol
Yo bro
@Darron Cherpak who actually believes this crap
@Alfredo Cash bot number 2
Hey Nick, I watched all of your LeetCoding videos to help me prepare for my technical interviews. I was able to secure two offers from big tech companies (including a FAANG). I just wanted to thank you for making these videos and helping people like myself achieve their professional goals!
He teaches in which language and u wrote code in interviews in which language ??
@@abhi.r8 he teaches in JAVA and I don't know about the second question
This guy rocks! I love his videos and explanations. I’ve been in the programming space for 21.5 years but I don’t get bored of listening to Nick White. He’s intelligent, enthusiastic, innovative and has excellent problem solving skills. This is the guy I’d like in my team.
Hey Nick!
Many students from India just like me watch your channel and learn logics with very easily readable code.
I just want to tell you that you are doing a great job and please keep the videos coming Everybody enjoys your video not just because you solve the problem but because you solve them with a lot of ease and fun.
The actual kandane algorithm explanation starts at 6:50
When you were winding down with the wrap-up, that's usually when I close the videos and I didn't really appreciate the algorithm, but I was so happy to have it running in the background as you revisited it and then demonstrated why it works and that just cleared all the fog and it suddenly made perfect sense.
I like this Nick White's explanation. He is precise simple and short. He is not boring explanation like others who takes 30min explanation on every small topics. When you are on the flow and need some hints. You wouldn't like to listen to 30-40 min boring explanation.
Fun fact - Jay Kadane came up with this algorithm in under a minute after other researchers spent months working on different solutions.
that a lie innit, he well nicked the idea off of me uncle jamaal
Those other researchers is me.
wow what a nerd. shit took me 3 hours 🤓🤓
Researchers spent months while interviewers expect 30 minutes lmao.
But the irony is interviewer expect in 25 minutes with production ready code. So if you don't know algorithm in advance then very difficult to crack and if you know then anyone can solve in 10 minutes.
I like to watch your videos while taking dump every day at 1 pm as it helps to build the pressure in my abdomen.
What? 😳
You sound like a dumbass and you’re disrespecting this guy
Hahah
I've been trying to find a proper explaination for this algorithm for a day now and I finally understand how it works. Thank you so much
This is the clearest explanation of Kadane's Algo I've seen thus far
This is the BEST channel for learning algos and interviewing .
Fr
Your videos are the best! I’m preparing for a job switch and learning ds & algorithms, nobody explains the things like you do. Thank you so much for helping us out! Keep doing the good work!
People should be liking your videos a lot because you are putting this content out for free... Thanks for all the help
NIT - Magic at 12:58. Line#6 , cur became current_sum on click run tests. Just for fun (or i did not understand your sarcasm). Your videos rock.
Going back and explaining how we lost -2 and started over with 2 is amazing.
12:56 “people will say...” cuts the video and corrects the variable name lol
hahahahaha
Lmao
Was wondering what was gonna happen when he went to run the code lol
@@NickWhite use a visual platform how each line of code executes programme because many are suffering how logic internally works
Which variable, I don't see it?
I have not watch your video for more than 2 min and you nailed it with a good explanation , you are the best
I was on the fence about giving that like he asked for, but the little plug in 5:38 cemented it, liked from me, all day everyday, fuck yea for Nick White.
I spent 7 hours (whole night) reading the textbook and watching RUclips trying to understand this. Was about to give up my college until i saw this video.
One "preprocessing step" would be to throw away any leading and trailing negative numbers in the array since they cannot help, then apply Kadane's algorithm to whatever is left. So the solution to [-2, 2, 5, -11, 6] is the same as the solution to [2, 5, -11, 6] which is the same as the solution to [-4, -3, -2, 2, 5, -11, 6, -1, -99]
Finally someone with great technical skills AND communication skills on youtube!!
Hope that helps more to understand just added comment to the code to dry track.!!
int [] array= {-2,2,5,-11,6};
int max_sum=array[0]; //i.e -2
int current_sum=max_sum; //i.e -2
for(int i=1;i
Honestly, this is the best explanation I've seen on Kadane's. Thank you!
your content is amazing, its way too good to be true
Damn. I was going though Priority Queues similar to a Huffman encoding tree combing Max Sum pairs into new nodes and leafs, but your solution was much easier. Nice work!
I love the energy and confidence. It boosts up one's coding brain :)
This channel deserves more attention. Awesome explanation.
Your way of explaining things is awesome brother... 🔥
This algorithm helped me with a question I was struggling with, and now I'm able to solve it, thanks a lot.
very crisp and clear. Thanks. Small suggestion : I hope you organize your playlist topic wise
Dropping a like and a comment. This channel deserves so much more attention
Bro...!!! You deserve lot more than ...likes. I have shared your video ...with my mates.
If you ever find it hard to understand the implementation, just know that current_sum stores the sums of the Contiguous sub array. And if the sum is every less that the next element in the array, then it starts a new count.
Can we also solve it through recursion? Essentially breaking down arrays into two parts and returning max among them. Base case would be array size 1.
1) Array including first index and excluding last index
2) Array excluding first index and including last index
yes, I tried the same approach....It will work but I got TLE for some of the test cases.
PFA:
class Solution {
public int maxSubArray(int[] nums) {
int total=0;
for(int i=0;i
I like your approach of showing the code last. Liked and subscribed!
Code in Javascript:
function findMaxSubArray(ar) {
let currentSum = ar[0], maxSum = ar[0], index = 1;
while (index < ar.length) {
currentSum = ar[index] < (currentSum + ar[index]) ? (currentSum + ar[index]) : ar[index];
if (maxSum < currentSum) maxSum = currentSum;
index++;
}
return maxSum;
}
There is slight Correction in this code!
Initialize:
max_so_far = 0
max_ending_here = 0
Loop for each element of the array
max_ending_here = max_ending_here + a[i]
if(max_ending_here < 0)
max_ending_here = 0
if(max_so_far < max_ending_here)
max_so_far = max_ending_here
return max_so_far
kadanes is a must do question for all programmers
Awesome! The best explanation [and not just code walkthrough like many others] on the entire youtube!
Great!
You should also consider trying LC# 690 (employee importance) and LC# 543 (Diameter of binary tree).
Thank you Nick! It’s a really clear and straight explanation.
your way of approaching problem is amazing i have learn a lot from you thanks for such amazing videos
5:21 Shouldn't it be O(N^3) because you are taking the sum of the subarrays?
thankyou bro
Nice representation of dynamic programming
Great question - we will ask this one soon. Thanks for the idea!
If we run two loops, one for the first and one for the last number, and then we sum. So we start to compare which one is greater if we offset the first or the last (closing in).
Edit: I'm new to coding, I just came here to see which problems are expected to be solved.
Learning during ICPC prelimary contest .. Thanks Nick !
thank you, Nick. It is very well explained
Amazing man please please do more videos like that. I appreciate your hard work on this. Keep growing brother 😊😊😊
Liking before even watching! Thanks, man!
thank you so much, I'm a newbie, this video helped me understand easy than the others
Your explanation was 👌👌😍
Solution method/function is off. Try input array = {-2,2,5,-11,8,6,-7,10}. At 7th iterating;- current_sum = max(current_sum + arr[7], arr[7]). the result is current_sum + 10 = 14 + 10 = 24. Result should be 14
No, it is not, according to the algorithm, your current sum at 7th iteration is 8+6+-7 which is 7, 7+10 is 17 which is the new Max sum
I tried watching 2-3 other videos but my dumbass brain could only understand this explanation. Great job!
Lol I like how right before he runs to code to show that it works he jump cuts to it passing after he changed cur to current_sum at 12:55
Cur
Window that keeps moving right till current is less than 0. Then set start to right + 1
Your videos are really good and useful! Keep it up and don't stop posting!
Absolutely Brilliant!! Well explained!! Thanks a lot for your contribution.
Amazing explanation 🤩🔥🔥🔥
Great explanation
This was amazing ... Thanks Nick
I got this problem in my Amazon internship OA. Totally messed it up. Learned from my mistake.
Thanks Nick. Appreciate the help.
According to wikipedia Mr.Kadane came up with the algorithm in less than a minute
You are the best the way you explain the problem
i hit the like button for my man ; Nick White!
Watch a lot of videos and will do "like". you are doing an amazing job and I am learning a lot.
Hi Nick, i have a short Question: Is the Steem Account "iwudah" belongs to you and do you have recently published this Video here on the Steem Platform? Thanks in Advance - greetings, louis
I hope your channel gets more popular, this is top quality content. Also just a thing i noticed, the statement with x = max(a, a+b) is way cleaner and shorter than what I would typically write like an if and else statement 👍
Agreed, I noticed that too and thought wow, that's way cleaner than I would've done that lol
Gave you a like just to help, and this comment is also for the algorithm.
Man nice videos, it helped me understand the concept in very east manner
I like the explanation at all, but there is a slight logic improvement that can be made in line 5. Notice that we check for the greatest of nums[i] and nums[i]+ current_sum. It is the same as comparing nums[i] + 0 and nums[I] + current_sum. Substracting nums[i] from both sides gives us comparing 0 and current_sum. And our current_sum then must look like Max(0, current_sum) + nums[i]. Not that much of work, but looks a bit more perfect as for me. Still great video as always ❤
Thanks for this video! Is knowing bruteforce and Kane's aglo enough for this problem? Would interviewers usually ask to solve this in different approach like divide and conquer?
Good Screening Explanation...Keep it up
Sir can you make a video on how to calculate time and space complexity . Like i have seen many videos but still. For ex- take 1 example of all sorting techniques and tell us how to find time complexity and you can even modify the sorting technique and show us the new complexity....it will be of great help sir🥺
Wow! Thank you very much for the detailed explanation it really helped.
5:52 for O(n)
LIKE THE VIDEO, GUYS. We're obviously here learning from this video so LIKE IT.
Love it! I found gold when I found your channel!
Tried with several cases, with the methods you taught, how can we return the index of the subarray as well?
You could try keeping two pointers m and n for returning the indices of the subarray. We would update both m and n whenever we find a cur_sum that beats our max_sum and starts a new subarray sum (i.e current element > cur_sum). We would update only n if our cur_sum beats out our max_sum and we don't start a new subarray sum.
Hey Nick you forgot to change the cur to curr_sum at line 6. Btw, nice explaination.
The best explanation ever!!!!
Good explanation. Thank you.
"Please hit the like button. I don't know if that'll make you wanna do it less, but... gotta try!" Hahaha. Liked!
Lol the introduction is pretty straight forward
Thanks for these videos, you help me get back on track when feeling unmotivated (:
Hi there, thanks for the video, but when I submit the code following the ideas, the leetcode gives me a special case, when length of the array = 1, for example, then the output will be 2, so better get the length checked before the loop.
He calls the O(n^2) solution brute-force. The first solution I managed to come up with was O(n^3). Fml.
Great explanation I have seen Thanks
you are a genius man.
Great work brother keep it up...
You are the best❤️
Did you apply for SDE at Amazon, seems like you know more than enough to get in.
I was asked the same question in my amazon interview
class Solution {
public int maxSubArray(int[] nums) {
int curr_sum = nums[0];
int max_sum = nums[0];
for(int i=1;i
Cutest coding teacher on RUclipseee 💗
I mean best. Best. ☺️
Hi Nick, what would be a more complicated variation of this problem that may be asked in an interview ?
Hi Nick, Thanks so much for sharing this. QQ: Shouldn't max_sum be equal to zero initially?
Hey..Can you please continue your "Technical Interview Study Guide" series,it's quite helpful.
geeksforgeeks has some good articles
O(N) Time complexity where N is the number of elements in the inputArray
O(1) Space complexity or is it O(N)
Nick is this correct?
The space complexity of this algorithm is O(2) since there are only two integers that are stored, regardless of the input. Usually we remove the coefficients of Big O Notation, so if we do that to this the space complexity is O(1) [constant space]
Here is your like good man, excellent explanation!