Thanks, bro, I haven't found a simple and high-quality video like yours anywhere.
@ThinkFWD5 жыл бұрын
Please feel free to leave a comment and let me know what you think !
@ThinkFWD4 жыл бұрын
From user @ leetcode @dermatobia The solution above could be improved by not actually changing the input array to cache profits. we could actually remove a few lines of code and achieve the same output! .. we don't actually have to cache the profits in our prices array. Since the profit var does it indirectly already. :) var maxProfit = function(prices) { let buy = prices[0]; let profit = 0; for (let i = 0; i < prices.length; i++) { if (buy > prices[i]) { buy = prices[i]; } else { profit = Math.max(prices[i]-buy, profit); } } return profit; };
@sawyerburnett8319 Жыл бұрын
Good call. I was about to say this. In this case it doesn't add any value to update the array, and could cause confusion or bugs in the solution.
@jerryliu8622 жыл бұрын
I appreciate you sharing this video, It improves my coding skill.
@edetmmekut8093 жыл бұрын
Hi really cool explaination ,but u dont need to mutate the array that extra over head cost
@riturathinsharma59313 жыл бұрын
This is a great solution mate , but the best solution is “divide and conquer”.
@initialb8113 жыл бұрын
great stuff! small recommendation: can you add comments in your code as a way for viewers to follow along better? I find myself needing to scrub back a couple of times to review why something was written. This video is definitely easy enough to follow, but it's something I find myself needing to do since I'm binge watching your videos. =D Also, subscribed! Thanks for making these videos!
@ibeeliot4 жыл бұрын
i binge on your videos. keep it up.
@ThinkFWD4 жыл бұрын
will release one tonight :) stay tuned !
@kathiateran58263 жыл бұрын
Really appreciate your videos, you're great at explaining things!
@ThinkFWD3 жыл бұрын
Thanks! Appreciate it
@DmitriyMalayevProfile2 жыл бұрын
You're an awesome instructor. Can you please check why the volume is so low?
@pinkhairblackman81413 жыл бұрын
reason he set price[i]=0 is the edge case where you can never make a profit
@nurlanikhsan3692 Жыл бұрын
Nice
@ThinkFWD Жыл бұрын
Thanks
@kidoo1567 Жыл бұрын
U are best
@rakeshrockie32134 жыл бұрын
please solve more problems. love your videos
@ThinkFWD4 жыл бұрын
will do ! planning on putting a few more stay tuned
@OmarAhmed-xc7bs3 ай бұрын
Nice work and explanation but please remove the music, it is a big distraction, tysm.
@EshsUrbanPulseYT7 ай бұрын
How this is dynamic programming, could anyone please explain?
@KolaIL2 жыл бұрын
var maxProfit = function(prices) { let minprice = prices[0]; let profit = 0; for (let i = 0; i < prices.length; i++) { if (prices[i] < minprice) { minprice = prices[i]; } else if (prices[i] - minprice > profit) { profit = prices[i] - minprice; } } return profit };
@user-zp1dv4yh5e2 жыл бұрын
Hey, I tried you appraoach , but it's not working function findMaxProfit2(prices){ let buy = [0] prices[0] = 0 let profit = 0 for(let i = 1; i < prices.length ;i++){ if(buy > prices[i] ){ buy = prices[i] price[i] = 0 }else{ profit = Math.max(prices[i]-buy, profit) } } return profit }