Kadane's Algorithm - Maximum Sum Subarray (Amazon Coding Interview Question)
Vložit
- čas přidán 26. 07. 2024
- 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 - Věda a technologie
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
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.
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!
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'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
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
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
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?
People should be liking your videos a lot because you are putting this content out for free... Thanks for all the help
This is the clearest explanation of Kadane's Algo I've seen thus far
Awesome! The best explanation [and not just code walkthrough like many others] on the entire youtube!
Honestly, this is the best explanation I've seen on Kadane's. Thank you!
Dropping a like and a comment. This channel deserves so much more attention
I love the energy and confidence. It boosts up one's coding brain :)
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.
The actual kandane algorithm explanation starts at 6:50
your content is amazing, its way too good to be true
This channel deserves more attention. Awesome explanation.
This is the BEST channel for learning algos and interviewing .
Fr
Great question - we will ask this one soon. Thanks for the idea!
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!
Great!
You should also consider trying LC# 690 (employee importance) and LC# 543 (Diameter of binary tree).
I have not watch your video for more than 2 min and you nailed it with a good explanation , you are the best
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
Your videos are really good and useful! Keep it up and don't stop posting!
Thanks Nick. Appreciate the help.
Thank you Nick! It’s a really clear and straight explanation.
Awesome new vibe you got goin on. :D Thanks for the video!
Amazing man please please do more videos like that. I appreciate your hard work on this. Keep growing brother 😊😊😊
Wow! Thank you very much for the detailed explanation it really helped.
Thanks for these videos, you help me get back on track when feeling unmotivated (:
your way of approaching problem is amazing i have learn a lot from you thanks for such amazing videos
This was an amazing explanation!!!
I spent 7 hours (whole night) reading the textbook and watching CZcams trying to understand this. Was about to give up my college until i saw this video.
I like your approach of showing the code last. Liked and subscribed!
Watch a lot of videos and will do "like". you are doing an amazing job and I am learning a lot.
Your way of explaining things is awesome brother... 🔥
Learning during ICPC prelimary contest .. Thanks Nick !
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.
Liking before even watching! Thanks, man!
Absolutely Brilliant!! Well explained!! Thanks a lot for your contribution.
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
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]
This was amazing ... Thanks Nick
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
thank you, Nick. It is very well explained
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.
Finally someone with great technical skills AND communication skills on youtube!!
Bro...!!! You deserve lot more than ...likes. I have shared your video ...with my mates.
thank you so much, I'm a newbie, this video helped me understand easy than the others
hey continue to post such videos,i love it
great explanation, thanks man!
Great work brother keep it up...
The best explanation ever!!!!
Man nice videos, it helped me understand the concept in very east manner
This helps, thank you very much , great job ❣️👏
i hit the like button for my man ; Nick White!
Nice representation of dynamic programming
gr8 work Nick.
Gr8 explanation bro , even ads on ur channel are great altium stories
kadanes is a must do question for all programmers
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.
Bro, I really appreciate those videos. It would be really helpful if you come up with something about this problem 'closest pair of points on 2d plane'.
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.
You are the best the way you explain the problem
I normally lurk, but ill give you a like and post this comment since you've helped me learn a lot :)
Thanks bro :) more power to you!
You are the best❤️
Your explanation was 👌👌😍
hey your videos are really helpful.. keep up the good work, can you please create a playlist apart from "leetcode" topicwise?
Could yo do a vid on betweeness centrality? Great vid!
Great explanation
I love your intro.
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.
LOVE THISSS💯
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
Great explanation I have seen Thanks
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!
Amazing explanation 🤩🔥🔥🔥
you are a genius man.
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🥺
Here is your like good man, excellent explanation!
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 ❤
Would be helpful if u do more of these algorithm type videos
I tried watching 2-3 other videos but my dumbass brain could only understand this explanation. Great job!
5:50 😂😂😂 nick white taught me
Hey..Can you please continue your "Technical Interview Study Guide" series,it's quite helpful.
geeksforgeeks has some good articles
I like your way of explaining. More power to you , lots os success awaits for your channel💪💪🙏🔥🔥🔥🤩🤩
5:43 that was totally a Michael Cera moment lol
Window that keeps moving right till current is less than 0. Then set start to right + 1
best explanation - ty
Excellent!!
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
Thanks for this