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.
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.
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
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!
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🥺
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
Line 5 should be `inputArray[i] + inputArray[i-1] surely?? in the case of [-2, 2, 5, 20, 6, -5, 8] your code will return 36????? or have I lost my mind?
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.
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
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!
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
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.
Another badly worded question... contiguous can mean "sharing a common border", and border can have a meaning of "the edge or boundary of something", so just add up all the positive integers and we are done. The entire array is bounded by the lowest and highest indexes, thus we can pluck any of [-2, 2, 5, -11, 6], because from the definitions, they are bounded by both the lowest and highest indexes (0 and 4), and also bounded by brackets, thus ANY subset is still contiguous by definition. I pick 2 + 5 + 6 = 13. This guy said you cannot do that but I disagree because even doing that matches the definitions. I can start on Monday FB.
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.
consider your viewers are first grade kids. dont skip what u are about to explain . dont think "like u know what i mean" while u teach something . Pls finish off the exaplaination . dont give examples while u teach give a clearcut full length explaination that what people wants or else theres no use makes tons of videos .espically in this video 4.59 u are are about to say something but u literally just skipped . see nick not everyone are genius like u . however i liked the video
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 don't understand why are you using the math library for comparing the max sums instead of normal conditions ??? just to show off or there is a legit reason?
Print the sub array with the indexes. public static void printMaxSumSubArray(int[] nums, int length) { int max_sum = nums[0]; int current_sum = max_sum; int start=0; int end=0; for(int i=1; i nums[i]) { end = end + 1; current_sum = current_sum + nums[i]; } else { current_sum = nums[i]; start = i; end=i; } max_sum = Math.max(current_sum, max_sum); } System.out.println("Start index:"+start+", End index:"+end); for(int i=start; i
I was asked this in a coding interview recently. Pretty difficult to solve on a whiteboard, with limited time, and an audience. It wasn't pretty. I've been programming professionally for 25 years (principal level) - personally, I would never subject a candidate to this, and I question the wisdom of these sorts of interview problems. More than likely, they're selecting people who've seen a lot of interview problems, not necessarily good programmers or problem-solvers. I muddled through, with a few hints. It was one of the most stressful interview questions of my career. (Got the offer, didn't take it.) Interviews suck.
Well it's easy for them to do. Just pick one well established algorithm, design a question around it and see if people know it... I mean, the thing has a name, making it sound like someone quite knowledgable had to come up with the idea - not that it is common knowledge with which people came up on the spot.
Just because you've been doing it for 25 years with a bloated title doesn't mean you're actually good at it. You can surely find some mediocre companies to work for, but the best ones will want someone better. Sorry to hear about your experience.
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.
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?
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 an array denoting numbers of n different types of candies. A person is happy if he receives n-1 different types of candies.Find maximum no of persons who can be made happy. Sample:- 3 //size of array 7//Freq of first type of candies 3//freq. For second type 12//Freq. For 3rd type Output:- 10 Since we can distribute 7 pairs of {1st and 3rd type} and 3 pairs of {2nd and 3rd type} Please help me with this. I think this is a problem related to permutations and combinations but I really cannot figure it out..
Love your vids! Correct me if I'm wrong, but I believe your solution contains an error. The max sum and the current sum should be initialized to 0, not the first item in the array. Otherwise, line 5 will evaluate Math.max(-4, -2) instead of Math.max(-2, -2). I noticed this when I ran your solution against the same array, but with a positive 5 inserted at position 0: [5, -2, 2, 5, -11, 6]. The max sum came out to 15, which is incorrect.
I came back to see this comment all the others are just fanatics and didn't even try his solution, I really think he needs to update this video because many are just followers...
It's been ages but for those who would read this today, Nick is actually right. Both Current sum and Max sum should be initialized to the first item in the array. And the for loop would begin from index 1. Line 5 would evaluate to Math.max(0, 2) not Math.max(-4,-2) nor Math.max(-2,-2), thus everything would work well. Even trying the sample array you gave with his code, the result was 10 which is technically correct so maybe there was a typo(you most likely initialized your i in for loop to 0 not 1) or different logic in your code. Forgive me if his video has been updated and earlier he used 'var i = 0' but has now changed it to be 'var i = 1'. If his video/code has been the same since you made this comment, then he has always been right.
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.
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
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 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
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.
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
The actual kandane algorithm explanation starts at 6:50
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.
Gave you a like just to help, and this comment is also for the algorithm.
I think you made a typo in line 6. curr is not defined.
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.
He calls the O(n^2) solution brute-force. The first solution I managed to come up with was O(n^3). Fml.
Hey Nick you forgot to change the cur to curr_sum at line 6. Btw, nice explaination.
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
your content is amazing, its way too good to be true
I normally lurk, but ill give you a like and post this comment since you've helped me learn a lot :)
This is the BEST channel for learning algos and interviewing .
Fr
Line 6: wth is cur???
Typo 😂
Dropping a like and a comment. This channel deserves so much more attention
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!
Nick white... litterally very white!!...I must say!...kidding...nice explanation..thank you very much!!👍
I subscribe to practically no one. I almost like no one. I love your page. Great job. I liked bro. You remind me a young Michael Anthony Hall.
Where is codesignal's link?
Hey..Can you please continue your "Technical Interview Study Guide" series,it's quite helpful.
geeksforgeeks has some good articles
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
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🥺
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
Line 5 should be `inputArray[i] + inputArray[i-1] surely?? in the case of [-2, 2, 5, 20, 6, -5, 8] your code will return 36????? or have I lost my mind?
Hi Nick, Thanks so much for sharing this. QQ: Shouldn't max_sum be equal to zero initially?
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.
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
Amazing man please please do more videos like that. I appreciate your hard work on this. Keep growing brother 😊😊😊
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!
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
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.
5:21 Shouldn't it be O(N^3) because you are taking the sum of the subarrays?
thankyou bro
Another badly worded question... contiguous can mean "sharing a common border", and border can have a meaning of "the edge or boundary of something", so just add up all the positive integers and we are done. The entire array is bounded by the lowest and highest indexes, thus we can pluck any of [-2, 2, 5, -11, 6], because from the definitions, they are bounded by both the lowest and highest indexes (0 and 4), and also bounded by brackets, thus ANY subset is still contiguous by definition. I pick 2 + 5 + 6 = 13. This guy said you cannot do that but I disagree because even doing that matches the definitions. I can start on Monday FB.
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;
}
class Solution {
public int maxSubArray(int[] nums) {
int curr_sum = nums[0];
int max_sum = nums[0];
for(int i=1;i
I tried watching 2-3 other videos but my dumbass brain could only understand this explanation. Great job!
You're too fast when explaining the core of this logic. I don't understand why people do it. It's not a race.
Bro, I was watching this video for lunch, and the next leet code problem I did was exactly this one, what in the flying fuck
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.
I got this problem in my Amazon internship OA. Totally messed it up. Learned from my mistake.
consider your viewers are first grade kids. dont skip what u are about to explain . dont think "like u know what i mean" while u teach something . Pls finish off the exaplaination . dont give examples while u teach give a clearcut full length explaination that what people wants or else theres no use makes tons of videos .espically in this video 4.59 u are are about to say something but u literally just skipped . see nick not everyone are genius like u . however i liked the video
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 solved it like this - also linear time. good?
int main()
{
int array[NUM] = {-2,2,5,1,1,-11,6,5,4};
int i;
int max=0;
int tempsum=0;
for (i=0;i
This doesn't look like an easy problem that can be solved within 45 mins. How are such questions asked in interview?
interviewer: can you find a linear solution?
me: hell yeah bitch I watch Nick White, now whose your daddy?
Bro...!!! You deserve lot more than ...likes. I have shared your video ...with my mates.
Instead of current_sum, it should definitely be named as current_max_sum to be more understandable.
I used this technique to solve a problem and then I came to know this is technique has a name "kadane's algorithm".
i don't understand why are you using the math library for comparing the max sums instead of normal conditions ??? just to show off or there is a legit reason?
Print the sub array with the indexes.
public static void printMaxSumSubArray(int[] nums, int length) {
int max_sum = nums[0];
int current_sum = max_sum;
int start=0;
int end=0;
for(int i=1; i nums[i]) {
end = end + 1;
current_sum = current_sum + nums[i];
}
else {
current_sum = nums[i];
start = i;
end=i;
}
max_sum = Math.max(current_sum, max_sum);
}
System.out.println("Start index:"+start+", End index:"+end);
for(int i=start; i
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
I was asked this in a coding interview recently. Pretty difficult to solve on a whiteboard, with limited time, and an audience. It wasn't pretty.
I've been programming professionally for 25 years (principal level) - personally, I would never subject a candidate to this, and I question the wisdom of these sorts of interview problems. More than likely, they're selecting people who've seen a lot of interview problems, not necessarily good programmers or problem-solvers.
I muddled through, with a few hints. It was one of the most stressful interview questions of my career. (Got the offer, didn't take it.)
Interviews suck.
Well it's easy for them to do. Just pick one well established algorithm, design a question around it and see if people know it... I mean, the thing has a name, making it sound like someone quite knowledgable had to come up with the idea - not that it is common knowledge with which people came up on the spot.
Just because you've been doing it for 25 years with a bloated title doesn't mean you're actually good at it. You can surely find some mediocre companies to work for, but the best ones will want someone better. Sorry to hear about your experience.
@@dijoxx i don't think you read her whole comment! there is no need to be mean!
If this question is changed to maximum possible sum of alternate elements and display the sum.
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
hell, yeah, i have been watching white's video, so i can come up with linear run time solution :p
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.
Great explanation
Cutest coding teacher on RUclipseee 💗
I mean best. Best. ☺️
not sure why this is such a common question. very difficult o(n) time unless you've memorized it
Here is your like good man, excellent explanation!
Liking before even watching! Thanks, man!
What's the software you're using to shoot these videos and move the arrows around and what not?
74 -72 94 -53 -59 -3 -66 36 -13 22 73 15 -52 75
Does'nt work on this test case .
According to wikipedia Mr.Kadane came up with the algorithm in less than a minute
you'll get more likes if you explain the your approach
Your way of explaining things is awesome brother... 🔥
cur is not defined anywhere. I guess you meant current_sum
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?
You are the best❤️
Good Screening Explanation...Keep it up
thank you, Nick. It is very well explained
Can you please help me identify max array permutations
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
People should be liking your videos a lot because you are putting this content out for free... Thanks for all the help
Lol the introduction is pretty straight forward
This is the clearest explanation of Kadane's Algo I've seen thus far
How to get that subarray…. i.e (2,5)
Nice representation of dynamic programming
LOVE THISSS💯
I liked n going to comment each video don't worry
Hey hey hey my love 💓 how is your mood right now .....
Great question - we will ask this one soon. Thanks for the idea!
Wow! Thank you very much for the detailed explanation it really helped.
Liked it
You change the variable name before run 😂
Awsm teacher
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.
because I watch Nick Whites videos
I love the energy and confidence. It boosts up one's coding brain :)
Is line 6 an error? i think its meant to be currentsum not curr
There is an array denoting numbers of n different types of candies.
A person is happy if he receives n-1 different types of candies.Find maximum no of persons who can be made happy.
Sample:-
3 //size of array
7//Freq of first type of candies
3//freq. For second type
12//Freq. For 3rd type
Output:- 10
Since we can distribute 7 pairs of {1st and 3rd type} and 3 pairs of {2nd and 3rd type}
Please help me with this.
I think this is a problem related to permutations and combinations but I really cannot figure it out..
Love your vids! Correct me if I'm wrong, but I believe your solution contains an error. The max sum and the current sum should be initialized to 0, not the first item in the array. Otherwise, line 5 will evaluate Math.max(-4, -2) instead of Math.max(-2, -2). I noticed this when I ran your solution against the same array, but with a positive 5 inserted at position 0: [5, -2, 2, 5, -11, 6]. The max sum came out to 15, which is incorrect.
I was searching for this comment..!
I came back to see this comment all the others are just fanatics and didn't even try his solution, I really think he needs to update this video because many are just followers...
It's been ages but for those who would read this today, Nick is actually right. Both Current sum and Max sum should be initialized to the first item in the array. And the for loop would begin from index 1.
Line 5 would evaluate to Math.max(0, 2) not Math.max(-4,-2) nor Math.max(-2,-2), thus everything would work well. Even trying the sample array you gave with his code, the result was 10 which is technically correct so maybe there was a typo(you most likely initialized your i in for loop to 0 not 1) or different logic in your code.
Forgive me if his video has been updated and earlier he used 'var i = 0' but has now changed it to be 'var i = 1'. If his video/code has been the same since you made this comment, then he has always been right.
The for loop should start with i = 1, if you start it with i=0, you get 15 which is wrong.
Let's help with that RUclips algorithm
At long last! I am watching your videos for couple months and finally when I saw your new video I said: nah, i know that, no need to analyze this :D
please make more videos on DSA......
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.