Profitable Schemes - (AMAZON) | Recur+Memo | Leetcode-879 | Live Code + Explanation

  Рет қаралды 3,537

codestorywithMIK

codestorywithMIK

Күн бұрын

This is the 25th Video on our Dynamic Programming (DP) Playlist.
In this video we will try to solve a very good DP Problem "Profitable Schemes" (Leetcode - 879)
Trust me, this will no longer be a Hard Problem. I will explain the intuition so easily that you will never forget.
We will solve it using Recursion + Memoization technique
Later we will post another video in which we will solve it using Bottom UP DP
We will do live coding after explanation and see if we are able to pass all the test cases.
Problem Name : Profitable Schemes
Company Tags : AMAZON
My solutions on Github : github.com/MAZ...
Leetcode Link : leetcode.com/p...
My GitHub Repo for interview preparation : github.com/MAZ...
Subscribe to my channel : / @codestorywithmik
╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
#coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #hindiexplanation #hindiexplained #easyexplaination #interview #interviewtips
#interviewpreparation #interview_ds_algo #hinglish

Пікірлер: 63
@NamanSharma-zx6gq
@NamanSharma-zx6gq Жыл бұрын
Sir, I have been watching your videos regulary and because of that I was able to solve today's question all by myself. Thank you , because of your videos I am able to improve my problem solving
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Apologies for the delay guys. Little busy this week due to festival. Hope you guys will understand ❤️❤️❤️
@kamleshsinghbisht130
@kamleshsinghbisht130 Жыл бұрын
Eid Mubarak Bhai Jaan💓
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Eid Mubarak Kamlesh. Thank you so much ❤️❤️❤️
@turing_machine544
@turing_machine544 Жыл бұрын
Eid Mubarak Bhaiya
@kamleshsinghbisht130
@kamleshsinghbisht130 Жыл бұрын
@@codestorywithMIK Keep Up The Good Work!
@sanjaykatta6499
@sanjaykatta6499 11 ай бұрын
I have almost solved a hard problem. Just got stuck at memoizing the third component profit, otherwise I almost did it. Thank you for all your explanations and intuition building. It would've never been possible otherwise.
@niteshk0487
@niteshk0487 Жыл бұрын
question dekhne ke bd or read krne ke bd itna hard lga sb sir ke upr se gya after watching your explanation easy or wot🤣❤❤
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Time Complexity :- O(N*M*K) N is the maximum number of criminals allowed in a scheme, M is the size of the list group, and K is the value of minProfit. Space Complexity :- O(N*M*K)
@ManojKrVerma-vw4dx
@ManojKrVerma-vw4dx Жыл бұрын
if v r nt memoising its time complexity is 2^N . Am I correct ?
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Yes because at each position you have two choices. So TC is exponential
@anuppatankar4294
@anuppatankar4294 Жыл бұрын
Watched your explanation and solved it myself. Great Video ❤
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Awesome Anup ❤️❤️❤️
@codewalalove8783
@codewalalove8783 Жыл бұрын
Sir, apki vedio ka morning se wait kr rahe hai, i saw 3-4 vedio more before that of same question, but smj nhi aya. I really like your way of explaning the things.Thnak You :)
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Awesome. So glad. Thank you so much ❤️❤️❤️
@souravjoshi2293
@souravjoshi2293 Жыл бұрын
I see many videos, but the satisfaction comes from your videos. Thanks a lot Eid Mubarak
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Thanks a lot Eid Mubarak ❤️❤️
@k_CO_Sachin
@k_CO_Sachin 7 ай бұрын
Amazing the idea to take minimum.... I was stuck at this step
@shikharpandya4927
@shikharpandya4927 Ай бұрын
Thank u sir did it on my own
@vineetkumar2899
@vineetkumar2899 Жыл бұрын
Thank you so much for this awesome explanation of hard problem. Eid Mubarak Bhaiya.💥💫
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Thanks a lot Vineet ❤️❤️❤️
@romanraihan9133
@romanraihan9133 Жыл бұрын
long long not_taken = solve(i+1, p, people, minProfit, group, profit)%mod; long long taken = solve(i+1, min(p+profit[i], minProfit), people+group[i], minProfit, group, profit)%mod; we are doing mod here. so we don't need to do (taken%mod + not_taken%mod)%mod; only (taken + not_taken) %mod; should work. just a simple improvement. Thanks for the tutorial. I was waiting since 6am for this video.
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Yep yep absolutely correct. Thanks a lot ❤️
@iamnoob7593
@iamnoob7593 2 ай бұрын
Again fantastic Explanation
@prajwalshaw9217
@prajwalshaw9217 Жыл бұрын
Thanks for a wonderful explanation sir. But facing a bit problem while coming up with it's bottom up approach...eagerly waiting for the bottom up approach of this question.
@saurabhkumarsingh9550
@saurabhkumarsingh9550 Жыл бұрын
Nicely explained.... I am new to your channel... I must say your explanation is good.
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Thank you so much Sourabh and welcome to my channel ❤️❤️
@arjunsolanki2612
@arjunsolanki2612 Жыл бұрын
Once again thank you bhaiya. Eid mubarak❤
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Thanks a lot Eid Mubarak ❤️❤️
@abc-ym4zs
@abc-ym4zs Жыл бұрын
I am your new subscriber I saw your channel in the linkedin saying u are approach to a problem is really good like on which topic your uploading questions dialy how to get maximum of your playlist how to follow your playlist sir
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Thanks a lot. Welcome to my channel. Right now I post Leetcode Daily Challenge And if you checkout my channel, it has playlists for different topics. If you want to make Graph easy, you can start my “Graph Concepts & Qns” playlist.
@abc-ym4zs
@abc-ym4zs Жыл бұрын
@@codestorywithMIK ok sir
@humanity7880
@humanity7880 Жыл бұрын
That minProfit wala explanation was too good,but can you explain me one thing: before that i was trying to do by making a dp[101][101][10001] by assuming that maxProfit will be of 10000 because in question was given profit[i]'s max value is 100 and profit's max length is 100 so i take 100*100=10000 and +1 that makes it dp[101][101][10001] but that was not working. Am i right profit dows not exceed 10000?
@Imrockonn
@Imrockonn Жыл бұрын
🎉
@codeandtalk6
@codeandtalk6 Жыл бұрын
@naeemkhan4534
@naeemkhan4534 Жыл бұрын
Bro What do you use to record the videos? Which tablet and software
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Ipad 11 pro I use default Notes app in it and use default screen recording
@shaamidrees6036
@shaamidrees6036 Жыл бұрын
Thanks you brother
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Thanks a lot Eid Mubarak ❤️❤️
@Tech_Creater_
@Tech_Creater_ Жыл бұрын
Could you explain this question in dp tabular method ?
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Sure. Will upload soon. Just a little occupied now due to festival
@manimanohar_001
@manimanohar_001 Жыл бұрын
Bhaijaan Eid Mubarak🌛.
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Eid Mubarak ❤️❤️❤️
@YashSinghal
@YashSinghal Жыл бұрын
new mic ?🤔 Eid mubarak 🎉🌙
@codestorywithMIK
@codestorywithMIK Жыл бұрын
No new mic yet. But soon ❤️ Eid Mubarak ❤️❤️
@ManojKrVerma-vw4dx
@ManojKrVerma-vw4dx Жыл бұрын
why are u checking whether we found one way after reaching end of the array. Is it not correct to say as soon as we get one way we should increase the count by 1?
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Because we want to explore different paths. And if we return as soon as we get minProfit, then we might miss other profitable paths from that point further
@ManojKrVerma-vw4dx
@ManojKrVerma-vw4dx Жыл бұрын
@@codestorywithMIK as soon as we get minProfit we increase the count by 1 and continue exploration further I never say return. I was doing the same and getting the answer always more than the actual answer. Why ?
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Can you share your code
@codestorywithMIK
@codestorywithMIK Жыл бұрын
You need to ensure that you dont exceed the number of members greater than n
@ManojKrVerma-vw4dx
@ManojKrVerma-vw4dx Жыл бұрын
@@codestorywithMIK Here is my recursive code void helper(int idx, vector& group, vector& profit, int pprofit, int minProfit, int persons, int maxPersons, int sz, int &cnt){ if (idx >= sz) return ; if (pprofit >= minProfit and persons < maxPersons) cnt++; // option 1 leave this group helper(idx+1, group, profit, pprofit, minProfit, persons, maxPersons, sz, cnt); // select this group if possible if (persons+group[idx] = minProfit and persons < maxPersons) cnt++; return ; }
@informative180
@informative180 Жыл бұрын
u r too gud..❤
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Thank you so so much
@shivangiagrawal3971
@shivangiagrawal3971 Жыл бұрын
pls share today's daily leetcode question sooner
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Hello Shivangi, Actually I couldn’t get time to post today’s leetcode due to festival. But feel free to find the code in my Github repo. And i will post tomorrow.
@shivangiagrawal3971
@shivangiagrawal3971 Жыл бұрын
@@codestorywithMIK ok Eid Mubarak ji apko
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Thank you for understanding Shivangi. Eid Mubarak 😊
@atifhu
@atifhu Жыл бұрын
EID MUBARAK🌙
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Eid Mubarak ❤️❤️
@anubhavsingla3126
@anubhavsingla3126 Жыл бұрын
class Solution { int MOD = 1000000007; public int solve(int n, int p, int i, int[] group, int minProfit, int[] profit, int[][][] dp) { if(i == group.length) { return p >= minProfit ? 1 : 0; } if(dp[i][n][p] != -1) return dp[i][n][p]; int ans = 0; ans = solve(n, p, i+1, group, minProfit, profit, dp); if(n - group[i] >= 0) ans += solve(n - group[i], Math.min(p+profit[i], minProfit), i+1, group, minProfit, profit, dp); return dp[i][n][p] = ans % MOD; } public int profitableSchemes(int n, int minProfit, int[] group, int[] profit) { int[][][] dp = new int[group.length+1][n+1][minProfit+1]; for(int[][] row: dp) { for(int[] col: row) { Arrays.fill(col, -1); } } return solve(n, 0, 0, group, minProfit, profit, dp); } } java version of recur + memo
@AnkitSingh-tm5dp
@AnkitSingh-tm5dp Жыл бұрын
I solve almost 90% but memo give some pain after understand the logic of min(profit+curr,miniproft) 🥲 i feel coding is really interesting thanku sir
@codestorywithMIK
@codestorywithMIK Жыл бұрын
So glad Ankit. 90% is all that I want. Soon very soon, we all will reach 100% together 💪💪💪 Thank you so much ❤️❤️❤️
@voice6905
@voice6905 Жыл бұрын
But I didn't understand why min(profit, profit[i] + currentProfit) works?
Não sabe esconder Comida
00:20
DUDU e CAROL
Рет қаралды 39 МЛН
Сюрприз для Златы на день рождения
00:10
Victoria Portfolio
Рет қаралды 2,4 МЛН
Good teacher wows kids with practical examples #shorts
00:32
I migliori trucchetti di Fabiosa
Рет қаралды 13 МЛН
638. Shopping Offers | DYNAMIC PROGRAMMING | RECURSION
12:46
code Explainer
Рет қаралды 301
Profitable Schemes - Leetcode 879 - Python
21:32
NeetCodeIO
Рет қаралды 8 М.
Good Book about Low-Level C++ [from a quant dev]
7:04
The Quantitative Developer
Рет қаралды 3,6 М.
How I Approach a New Leetcode Problem (live problem solving)
25:31
Algorithms Explained for Beginners - How I Wish I Was Taught
17:38
Internet Made Coder
Рет қаралды 357 М.
❌ Don't Run Behind 500 LEETCODE Problems ❌ Focus on QPCD
8:31
Não sabe esconder Comida
00:20
DUDU e CAROL
Рет қаралды 39 МЛН