Coin Change 1 & 2 : Leetcode DP Questions | CP Course | EP 93

  Рет қаралды 49,356

Luv

Luv

Күн бұрын

Пікірлер: 123
@anonymous13679
@anonymous13679 2 жыл бұрын
Thank you Luv, Can you also make a tutorial for Graph and Flows?
@ChandraShekhar-by3cd
@ChandraShekhar-by3cd 2 жыл бұрын
Thanks a lot for the Leetocde video . Please continue with the Leetcode Daily challenge series. Thanks💛
@anshulkumar7871
@anshulkumar7871 2 жыл бұрын
Please complete whole DSA series before November. I understand everything you teach.
@PoojaSharma-nt3ge
@PoojaSharma-nt3ge 4 ай бұрын
The important difference nobody tells you! 🙌🏻🙌🏻🙌🏻 very well explained
@codesouls2441
@codesouls2441 Жыл бұрын
Love you man. Only because of you I am able to understand dynamic programming and finally solve some problems with it. You are amazing. Thanks for this playlist.
@Naturalbanarasi
@Naturalbanarasi 4 ай бұрын
Very intuitive approach to problems bhaiya.
@shubhsiroliya1213
@shubhsiroliya1213 2 жыл бұрын
coin change 2 can be made in a separate video & code must have to be explained from scratch because two approaches are quite different from each other & it is hard (very time consuming) to successively watch both the videos & interpret both the algos . You're doing an amazing work keep it up , just letting you know what difficulty I faced . otherwise content is rich in quality . Thanks .
@jonayedmohiuddin538
@jonayedmohiuddin538 Жыл бұрын
class Solution { public: int dp[310][5010]; int func(int amount, vector &coins, int curr) { if(amount == 0) return 1; if(dp[curr][amount] != -1) return dp[curr][amount]; int ways = 0; for(int i = curr; i < coins.size(); i++) { if(amount - coins[i] >= 0) { ways += func(amount-coins[i], coins, i); } } return dp[curr][amount] = ways; } int change(int amount, vector& coins) { memset(dp, -1, sizeof(dp)); sort(coins.begin(), coins.end()); return func(amount, coins, 0); } }; I tried it this way by changing the code for coins change 1.
@kuldeep-ju7iy
@kuldeep-ju7iy Жыл бұрын
exactlyy.. why he is not replying anyones comments here he made promises of : /
@sahilanand30
@sahilanand30 2 жыл бұрын
Clear and concise explanation
@harishsharma2892
@harishsharma2892 2 жыл бұрын
in minimum coins if we use a test case in which no combination is possible we are not getting -1 as ans from this code if we use case like ampunt=7,n=3,coins={3,6,3} I m getting 1 as ans as it will go inside the loop .
@gilbertopsantosjr
@gilbertopsantosjr 10 ай бұрын
what's the whiteboard are u using ? can u share the link ?
@AmanKumarSinhaOfficial
@AmanKumarSinhaOfficial 2 жыл бұрын
Please Make Videos on CodeForces Questions
@fitness11257
@fitness11257 2 жыл бұрын
trie ke upar bhi banao videoes
@lokeshmehta9591
@lokeshmehta9591 2 жыл бұрын
ultimate effort
@nopecharon
@nopecharon Жыл бұрын
you are too good in teaching
@ritodhwajsen8205
@ritodhwajsen8205 2 жыл бұрын
Great explanation. Lovet it
@abhijeetsingh9796
@abhijeetsingh9796 2 жыл бұрын
Sir, minimum coins required ko greedily nhi kar sakte kya?
@jonayedmohiuddin538
@jonayedmohiuddin538 Жыл бұрын
class Solution { public: int dp[310][5010]; int func(int amount, vector &coins, int curr) { if(amount == 0) return 1; if(dp[curr][amount] != -1) return dp[curr][amount]; int ways = 0; for(int i = curr; i < coins.size(); i++) { if(amount - coins[i] >= 0) { ways += func(amount-coins[i], coins, i); } } return dp[curr][amount] = ways; } int change(int amount, vector& coins) { memset(dp, -1, sizeof(dp)); sort(coins.begin(), coins.end()); return func(amount, coins, 0); } }; I tried it this way by changing the code for coins change 1.
@mehoneybadger999
@mehoneybadger999 2 жыл бұрын
sr, ek baat bata do bs, for dp, agar mujhe iterative approach nahi aata, ya mai iterative approach me weak hu, to companies interviews or selection process pr kya affect hoga?
@ChirameTanishqArvind
@ChirameTanishqArvind 4 ай бұрын
music name ?! at the end and start of the video ?
@kuldeep-ju7iy
@kuldeep-ju7iy Жыл бұрын
how can you ensure in the questio which was asking for minimum coins that the coins which we got our answer are making the amount zero..
@musicascade4408
@musicascade4408 2 жыл бұрын
absolute stunner exlpanation!
@viki2479
@viki2479 2 жыл бұрын
💛.bhiya if thecondition , if(dp[index][amount] != -1) return dp[index][amount]; is placed before other if conditions , then the program is not working.could you explain why?
@mkitrixxmusic4023
@mkitrixxmusic4023 2 жыл бұрын
because index can go to negetive and accesing negetive indexed memory is not allowed :)
@pawankumarpandit1822
@pawankumarpandit1822 Жыл бұрын
what a amazing explanation bhaiya
@anshulagarwal6682
@anshulagarwal6682 2 жыл бұрын
If we are type casting in func(amount - coin)+1LL then it will cross INT_MAX and condition ans == INT_MAX?-1: ans should not return -1.
@raunakkumar6144
@raunakkumar6144 2 жыл бұрын
Think carefully , when will above function return int max. It will return int max only when making v with given coins is not possible(like making odd V with all even coins etc) so min from ans which is int max and int max +1 is int max
@varunsharma2876
@varunsharma2876 2 жыл бұрын
Very well explained !!🙂
@abhinavpandey3356
@abhinavpandey3356 2 жыл бұрын
Min coins wale ki complexity kitni hogi o(Len of aray*height of recur tree) is it correct? Height of tree can be upto the max element of array
@_inspireverse___
@_inspireverse___ 2 жыл бұрын
I'm little confused In knapsack problems either we take current element or skip . So we have to call 2 times recursive function. dontTake = func(amount , coins); take = 1 + func(amount - coin, coins); But you took only second case . Why???
@shahbazp1
@shahbazp1 2 жыл бұрын
'don't take' scenario will be covered automatically since there is a loop iterating through each coin denomination.
@codecorn8030
@codecorn8030 Жыл бұрын
This happens when u see striver and Luv together 😂😂
@divyampatro8586
@divyampatro8586 2 жыл бұрын
Great video Luv, I was wondering about the time complexity for Coin Change 2, it should be O(N*M*M) where N = coins.size() and M = amount. #Recursive calls = O(N*M), and computations per call = O(M). Am i right?
@iamluv
@iamluv 2 жыл бұрын
Salute inside every recursion is not a linear Loop only for coin of Rs.1 it will be linear even for coin of Rs.2 it will become a login loop and soon it will go on decreasing hence approximately it is near to NM only
@divyampatro8586
@divyampatro8586 2 жыл бұрын
@@iamluv Agreed! Thanks for replying dude :)
@strugglingprogrammer1487
@strugglingprogrammer1487 2 жыл бұрын
Love you Luv bro, for such as wonderful video of DP
@saikatthegreat5925
@saikatthegreat5925 Жыл бұрын
Why do you prefer memoization over tabulation? I just submitted this question on leetcide seeing your video, I submitted using memoization, it said I beat 6% of the cpp submissions in runtime. Then I gave the code to chatgpt and said to reduce runtime. He used tabulation and it beats 97% of cpp submissions. I said don't use tabulation, try reducing with memoization. He tried but the code gave wrong answer that means to me that the code cannot be optimized more.
@PoojaSharma-nt3ge
@PoojaSharma-nt3ge 4 ай бұрын
The selection of the similar problems to explain the difference is very well thought!
@codecorn8030
@codecorn8030 Жыл бұрын
Bhaiya pls tell ....why the below code for the same problem with ur approach only Is giving TLE ? ------------------------------------------------------------------ static const int N = 1e5+10; int MinC[N]; int MinCoins (int sum , vector&a) { if (sum < 0) return -1; if(sum==0) return (MinC[sum]=0); if (MinC[sum] != -1) return MinC[sum]; int ans = INT_MAX; for (int i = 0; i < a.size(); ++i) { int prev = -1; if(sum-a[i]>=0) prev = MinCoins(sum - a[i], a); if (prev != -1) { ans = min(ans, 1 + prev); } } if (ans != INT_MAX) MinC[sum] = ans; return MinC[sum]; } int coinChange(vector& coins, int amount) { memset(MinC,-1 , sizeof(MinC)); return ( MinCoins(amount , coins) ) ; }
@mumbailover-sp7tk
@mumbailover-sp7tk Жыл бұрын
bhaiya where i am getting wrong while applying second approach to first coin change problem of finding minimum count of coins required bhaiya please reply fast #include using namespace std; const int N=1e5+10; const int M=301; int dp[M][N]; int func(int index,int amount,vector &coins){ if(amount==0){ return 0; } if(indexn>>amount; memset(dp,-1,sizeof(dp)); vector coins(n); for(int i=0;i>coins[i]; } int ans=func(coins.size()-1,amount,coins); if(ans==INT_MAX){ cout
@lordvoldemort17727
@lordvoldemort17727 Жыл бұрын
can someone explain the coinchange2 algo. i didnt understand it completely
@ankita7119
@ankita7119 Жыл бұрын
same
@SilentKiller-tp9pu
@SilentKiller-tp9pu 2 жыл бұрын
@anshulagarwal6682
@anshulagarwal6682 2 жыл бұрын
I was unable to submit Coin Change 2 through this solution because Memory Limit was exceeded. How can we optimize memory?
@pulkitdang
@pulkitdang Жыл бұрын
Can the coin1 code be modified to get the list of coins constituting the minimum number of coins required to create that particular amount?
@leninsingh5264
@leninsingh5264 2 жыл бұрын
Can someone explain the iteration for(int coin: coins), How the values are stored on ans and iterating.?
@rishav144
@rishav144 2 жыл бұрын
thanks 🔥
@shivamcoli3073
@shivamcoli3073 2 жыл бұрын
sir ek video minimum difficulty of job schedule pe banao
@SyedAli-gu2hp
@SyedAli-gu2hp Жыл бұрын
16:43 it's can be a meme "Kyu hora hai mera sath aisa"
@avanshikasingh2054
@avanshikasingh2054 2 жыл бұрын
I really like your video. Great work 👌 Please when ever you write new fun() write it from starting . Just not edit it I just get confused some time.
@ameykhurdekar4980
@ameykhurdekar4980 2 жыл бұрын
very helpfull thankyou very much
@abhishek04204
@abhishek04204 2 жыл бұрын
Is this question comes under unbounded knapsack ??
@romanrai2507
@romanrai2507 2 жыл бұрын
Best as always❤
@RISHAVKUMAR-kx5up
@RISHAVKUMAR-kx5up Жыл бұрын
Sir z function ki ek video bana do please
@kishan2
@kishan2 2 жыл бұрын
Can any tell me, why am i getting TLE with this code of coin change 1 problem: int dp[13][10001]; int func(int idx, int amount, vector coins) { if (amount == 0) return 0; if (idx < 0) return INT_MAX; if (dp[idx][amount] != -1) return dp[idx][amount]; int ans = INT_MAX; for (int n = 0; n * coins[idx]
@yashvardhansinghsolanki659
@yashvardhansinghsolanki659 Жыл бұрын
pass vector by reference in func
@CodeDaily29
@CodeDaily29 6 ай бұрын
can anybody explain about INT_MAX?
@Kaushikraj9845
@Kaushikraj9845 2 жыл бұрын
But why did you select graph tree..why not regular formula of division and mod
@pkyadav6230
@pkyadav6230 Жыл бұрын
Bhai music kaon sa hai
@chiraggoyal9646
@chiraggoyal9646 2 жыл бұрын
Thanx bhaiya
@Ash-fo4qs
@Ash-fo4qs 2 жыл бұрын
same code not working in leetcode? anyone
@mkitrixxmusic4023
@mkitrixxmusic4023 2 жыл бұрын
leet code gigving me tle for the same code in coin change 2 :)
@funenjoynilaypatel4553
@funenjoynilaypatel4553 2 жыл бұрын
16-aug 2022
@AKumar11111
@AKumar11111 2 жыл бұрын
Koi ye batao ki ans INT_MAX ke equal kase ho raha hai
@unknown_coder7960
@unknown_coder7960 2 жыл бұрын
Bhaiya ab 870 questions aur 🙂
@kripanshbhalla9782
@kripanshbhalla9782 Жыл бұрын
cses aur vscode par nhi chal rha, leetcode par chal raha, hows that possible!! dimag kharab hogya h..
@jasmeenkaur6001
@jasmeenkaur6001 2 жыл бұрын
coin change 1 mien 2nd que vali approach work ni kr rhi bhaiya int dp[13][10010]; int Func(int index, vector& coins,int amount){ if(amount==0) return 1; if(index
@chrisharris1892
@chrisharris1892 2 жыл бұрын
isliye nahi work kar rahi yah approach kyunki minimum number of coins find karne ke liye index-1 kar rahi ho par wo galat hai. Index ki koi zarurat nahi hai kyunki sequence order matter nahi karta yaha.
@princhipawansaikia
@princhipawansaikia 2 жыл бұрын
💛💛💛
@hemantsingh2331
@hemantsingh2331 Жыл бұрын
💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛💛
@subhasishpanda5390
@subhasishpanda5390 2 жыл бұрын
💛
@sureshasuresha3571
@sureshasuresha3571 2 жыл бұрын
👌👌
@p38_amankuldeep75
@p38_amankuldeep75 2 жыл бұрын
💛💛💛💛💛💛
@dhruvyadav3492
@dhruvyadav3492 2 жыл бұрын
💚
@soumavachakraborty9858
@soumavachakraborty9858 2 жыл бұрын
💛💛💛💛💛
@DailysharmaKivines
@DailysharmaKivines 2 жыл бұрын
@Good-tz8ep
@Good-tz8ep 2 жыл бұрын
❤️💕💕❤️
@lakshyakhushalani9464
@lakshyakhushalani9464 2 жыл бұрын
bhaiya atleast pehle samjhao toh sahi hum begineers ko ki ques ko dekhkar kese samjhee ki yeh dp se hi hoga ya recursion se hi hogaaaaa......pehle general way toh samjhaoo
@harshitagrawal8859
@harshitagrawal8859 2 жыл бұрын
Plz don't call it basic sa code , its difficult for newbi to grasp
@namansharma5128
@namansharma5128 2 жыл бұрын
Code Using Knapsack Concpt--> class Solution { int dp[301][5001]; //finds the ways for getting amount using all the combos of coin at the current index. int find(int ind, int amt, vector& coins){ if(amt==0) return 1; if(ind < 0 || amt the above code will also consider the duplicates combination.
@ayushraj-lt4oc
@ayushraj-lt4oc Жыл бұрын
😂😂
@nishchayshroff7334
@nishchayshroff7334 2 жыл бұрын
💚💚
@tanvir4587
@tanvir4587 Жыл бұрын
🧡
@dipubiswas8359
@dipubiswas8359 Жыл бұрын
💛💛💛💛
@sayondeep5050
@sayondeep5050 2 жыл бұрын
💛
@chillkro25
@chillkro25 Жыл бұрын
🧡🧡
@good114
@good114 Жыл бұрын
💕♥️
@parivartan_._07
@parivartan_._07 2 жыл бұрын
💛💛💛
@champion5946
@champion5946 2 жыл бұрын
💛
@SohamJobanputra
@SohamJobanputra Жыл бұрын
💛💛💛💛
@_ayush_oswal
@_ayush_oswal 2 жыл бұрын
💛💛💛
@pulkitmittal584
@pulkitmittal584 2 жыл бұрын
💛
@jinniesrego
@jinniesrego 2 жыл бұрын
💛
@divyanshgupta5686
@divyanshgupta5686 2 жыл бұрын
💛
@virenderkumar951
@virenderkumar951 2 жыл бұрын
💛
@divyansh2212
@divyansh2212 2 жыл бұрын
💛💛
@shivi3157
@shivi3157 2 жыл бұрын
💛
@sahilanand30
@sahilanand30 2 жыл бұрын
💛
@aptitudepointiit-bhu5358
@aptitudepointiit-bhu5358 2 жыл бұрын
💛
@sanketkhonde4315
@sanketkhonde4315 2 жыл бұрын
💛
@harshitsamdhani2426
@harshitsamdhani2426 2 жыл бұрын
💛
@newmoviesarena780
@newmoviesarena780 2 жыл бұрын
💛
@than0s869
@than0s869 2 жыл бұрын
💛
@ayushmansingh3700
@ayushmansingh3700 Жыл бұрын
💛
@rakesh1147
@rakesh1147 Жыл бұрын
💛
@sanjaymajumder2991
@sanjaymajumder2991 Жыл бұрын
💛
@JIGARSINGTHAKOR-yy6qp
@JIGARSINGTHAKOR-yy6qp Жыл бұрын
💛
@NARUTOUZUMAKI-bk4nx
@NARUTOUZUMAKI-bk4nx Жыл бұрын
💛💛
@harshitsrivastav7343
@harshitsrivastav7343 11 ай бұрын
💛
@Red___Beast
@Red___Beast Жыл бұрын
💛💛
Coin Change - Dynamic Programming Bottom Up - Leetcode 322
19:23
Creative Justice at the Checkout: Bananas and Eggs Showdown #shorts
00:18
Fabiosa Best Lifehacks
Рет қаралды 33 МЛН
Lamborghini vs Smoke 😱
00:38
Topper Guild
Рет қаралды 53 МЛН
УДИВИЛ ВСЕХ СВОИМ УХОДОМ!😳 #shorts
00:49
Чистка воды совком от денег
00:32
FD Vasya
Рет қаралды 4,9 МЛН
15  Coin change problem: Maximum number of ways
21:16
Aditya Verma
Рет қаралды 316 М.
16  Coin change problem: Minimum number of coins
25:54
Aditya Verma
Рет қаралды 280 М.
DP 22. Coin Change 2 | Infinite Supply Problems  | DP on Subsequences
22:17
Coin Change - Leetcode 322 - Dynamic Programming (Python)
15:27
Dynamic Programming lecture #2 - Coin change, double counting
18:35
Errichto Algorithms
Рет қаралды 166 М.
Creative Justice at the Checkout: Bananas and Eggs Showdown #shorts
00:18
Fabiosa Best Lifehacks
Рет қаралды 33 МЛН