Coding Interview Question - Max Profit With K Transactions

preview_player
Показать описание

Ace the Programming Interviews with 65 video explanations of popular interview questions. Each question also comes with a workspace where you can code your solutions and run them against custom test cases, with hints, with written solutions in JavaScript, Python, C++, Java, and Go, and with a space-time complexity analysis of the algorithm at hand.
Рекомендации по теме
Комментарии
Автор

I was struggling with understanding the time optimization for 2 days but the way you put it across simplified it so much! Thank you for the very simplified explanation!

gourmand_knitter
Автор

This is probably the best explanation for a DP question. Thanks a ton for making this video.

harshjaiswal
Автор

Can't forget this voice... Thank you Clement

amandubey
Автор

Gotta say I was on the fence to watch/not watch this 48min video, but it is so worth it!

vinaykumardahiya
Автор

First I thought, 48 mins for this question is too much, but after watching i realised its worth it. Great Job!!

Abhishekkumar-mxjs
Автор

I was stuck with this problem for almost the entire day. I watched a lot of videos and went through so many solutions and discussion forums in leetcode. Still I just couldn't wrap my head around it. But you made it look so easy with your crystal clear explanation. It helped me so much. Thanks. Subscribing to you and hoping to find more of these video on your channel.

harishsn
Автор

the best explanation for the stock problem I've ever watched. No other video actually explains how to induce the formula and just shows the formula first and then fills out the matrix which is not good. But your explanation really tells how to induce formula which is really helpful to understand. I've known this problem for many years but I had to keep recap this whenever I need to prep. interview by almost memorizing it which makes me really frustrated and now truly understand since it's very time and energy consuming. Thanks a lot and hope you upload more videos.

satang
Автор

Clement, I have subscribed to the algoexpert course. People say that Algoexpert has just put questions from Leetcode and is not useful. However i found it to be extremely helpful because it covers patterns. And cracking a coding interview does not require to know all questions but the common patterns to solve problems. Its a very structured course and I have substantially improved my algo ds skills over time. Now I feel a hell lot more confident about big tech interviews.

phoneix
Автор

This is the best explanation I've seen of the problem. It came up as a LC challenge question recently. I was unable to formulate it in DP terms, but managed a backtracking solution. Thanks.

crankyinmv
Автор

Awesome explanation, literally no other explanation made sense for me. The optimization made no sense to me but you explained it so well that it just clicked

rayano
Автор

I was lost for a few days... then I found this video! Thanks!

giorgosk.
Автор

Hello,
I had some trouble understanding at first what was going on around 17:05 case 2 at first. A breakdown that makes more sense to me is:

you sell the stock at day d, but to sell the stock at day d, you must have bought the stock at some day x, 0 <= x <= d.
you then write the maximum profit you can make with one less transaction WHILE STILL HAVING BOUGHT THE STOCK as the maximum of profit[t - 1][x] - prices[x] .

Its also helpful to think of transactions instead as _sales_ I think.

jacobsalzberg
Автор

I always have hard time understanding this problem. Most of the videos explain formulas . I am glad that i came across this video, After watching this video i understand the problem well as well as dynamic programming. Many thanks to you

balajibala
Автор

Awesome Man.. I will actually prefer your videos only. You have explained this very well, Glad I bought the algoexpert subscription

YashArora
Автор

This explanation was crystal clear and the best I found for this complicated problem - thank you!

amyxst
Автор

I am not sure but there may be a way to get the complexity down. Where the complexity is at most big O of sorting the result array. In this case (BigO(nlogn))
List<int> prices = new List<int>() {5, 11, 6, 33, 6, 77, 8, 1, 66, 99, 46, 4, 234, 5, 6};
List<int> prices2 = new List<int>() {5, 11, 3, 50, 60, 90};

List<int> result = new List<int>(prices.Count) {0};
int reIndex = 0;
result.Add(0);
for (int i = 1; i < prices2.Count; i++)
{
if (prices2[i] - prices2[i -1] < 0)
{
reIndex++;
result.Add(0);
continue;
}
result[reIndex] += prices2[i] - prices2[i - 1];
}
result.Sort();
result.Reverse();
}

softwaredeveloper
Автор

this one of the difficult question even to understand infact you did a great job .

kalpkumudkumar
Автор

One feedback is to give users idea on how u came to approach this using dp

lemonginger
Автор

At 14:23, If we are selling at 50 at the end of 1st transaction how can we assume to buy again at 50 and add the profit of 4rth day?

shivanshrawat
Автор

Better than Tushar Roy. Please make more videos on Dynamic Programming problems.

akhilesh_singla