those who are facing run time error with the tabuation method in leetcode, please try to assign the vector dp. It will help in dealing integer overflow.
also what if i-nums[j] becomes > target. we are only checking the lower bound of index. why are we not the checking the case when index may become grater than the size of dp array
what if I want to print those ways, like in a list of list containing all the combinations Like {{1,1,1,1,1},{1,2,2},{2,3},{1,1,3},{1,1,1,2}} can we apply dp in that case, because as I observed many problems of dp covers "number of ways" or "count"
Hello love, recently I got question in one of my interview to check if circular linked list is sorted in ascending order or descending and find head can you help
I have a doubt, should time complexity of Recursion + Memoization solution be O(tar*n), where n is size of num array, as for every num, we are checking if target was met recursively....
Bhiya pata kese chalega ki base case reach hone pr Kab 0 return karna hai kab -infinity return karna hai Ya kab INT_MAX return karna hota hai Love from indore bhiya❣️
Java LeetCode Solution: class Solution { public int combinationSum4(int[] nums, int target) { //1D dp bcz only 1 para changing int[] dp=new int[target+1]; Arrays.fill(dp,-1); return helper(nums,target,dp); } private int helper(int[] nums, int target,int[] dp){ if(target==0) return 1; if(target
Recursion + memoization code , Beginners friendly. hope it helps. class Solution {
int dp[201][1001]; int f(int i, int k , vector & nums){ if( i == nums.size()) return(k ==0); if(dp[i][k]!= -1 ) return dp[i][k]; int p =0; int np = f(i+1 ,k,nums); if(k>=nums[i]) p=f(0,k-nums[i],nums); return dp[i][k] = p + np; } public: int combinationSum4(vector& nums, int target) {
those who are facing run time error with the tabuation method in leetcode, please try to assign the vector dp. It will help in dealing integer overflow.
yes it happened with me.
also what if i-nums[j] becomes > target. we are only checking the lower bound of index. why are we not the checking the case when index may become grater than the size of dp array
it cant be greater than the target as the nums array is always greater than zero so i - nums[j] is always less than the target
@@taneyasoni
Time Complexity is actually O(target * nums.size) and not O(target) .
4:50
Le machhar: I am the first one in my species who is friends with a human.
Thank you Bhaiya, Just keep going... More strength to you . This is helping us a lot✨✨✨✨
very good explanation bhaiya ,tablulation wala abhi acha seh visualise hua..
Sir pls also show dry run of tabulation code ...🙏🙏
Tabulation is not optimised than Memoisation in this Question bcz tabulation's Time Complaxity is O(n*m)
what if I want to print those ways, like in a list of list containing all the combinations
Like {{1,1,1,1,1},{1,2,2},{2,3},{1,1,3},{1,1,1,2}}
can we apply dp in that case, because as I observed many problems of dp covers "number of ways" or "count"
no we can't use dp there
Day 4 of DP | Completed
Bhaiya leetcode premium giveaway abi tak ni hua 😒😒
Named as perfect sum in GFG 👍🏻👍🏻 you can search it and solve it.
accha h accha h bahut acchaaaaaa. .. h :-)
Awesome explanation again. Keep posting videos.
I think there should a 4th step when using memoization...that is pass the dp array to recursive call so that we don't forget this.
Bhaiya ,, abhi kitna lectures aur baaki hai ??
started the course a month back, now on video 54th!
Hello love, recently I got question in one of my interview to check if circular linked list is sorted in ascending order or descending and find head can you help
sir 8:12 yaha par ans=1+solve() kyu nai kiya ans=ans+solve() kyu kiya
7:05
How many videos left in this series ?
Bhaiya dhud ka dhud or Pani ka Pani ho gya 💘 se
Bhai koi esa video banao jisme complete ROADMAP ho ARTS background ke STUDENTS KE LIYE
Koi development mai course laane ka plan hai kya bhaiya.....???
Series going awesome ☺️☺️
bro kitna time laga yaha tak pahuchane me
@@vinamrapatel4314 2.5 months.
can we solve this using the include exclude method
by applying for loop for each target we are already excluding previous ith element from num after i++
Bhaiya is series me kitte videos honge??
total 65 videos
including easy medium & hard quesions
I have a doubt, should time complexity of Recursion + Memoization solution be O(tar*n), where n is size of num array, as for every num, we are checking if target was met recursively....
Great explaination
If we want to print the all array from which we got the target so what is the approach
gr8 bhaiya
yahan base case 0 rakhun , aur recusrion ke answer + 1 storre krun to usme kya galat hai?
Maja aaya
Bhiya pata kese chalega ki base case reach hone pr
Kab 0 return karna hai kab -infinity return karna hai
Ya kab INT_MAX return karna hota hai
Love from indore bhiya❣️
thank you bhaiya
Bhaiya Online Assesment(For Faang) ke liye ek dedicated video chahiye with some resources please bana dijiye..
amazing
awesome
Tabulation method katai nhi samjh aa rha
why are we making dp of size target+1?
completed
Sir kitne or video aayenge c++ series ke
First time attend DP lecture I like it but plz ap. Thoda slow Bologe it will easy to. Understand
playback speed kam karle bhai , itna stress kyu lera h.
@@mikelan9854 are wo jo bolte hai wo bohot fast hai
can we do it using 2 D dp instead of for loop ?
willl be alot easier
Thanks sir
Bhaiya dp ka size n+1 q use Kiya h n nhi hoga?🤔
cause array starts from 0 not 1
Java LeetCode Solution:
class Solution {
public int combinationSum4(int[] nums, int target) {
//1D dp bcz only 1 para changing
int[] dp=new int[target+1];
Arrays.fill(dp,-1);
return helper(nums,target,dp);
}
private int helper(int[] nums, int target,int[] dp){
if(target==0) return 1;
if(target
why we took target+1 as the size of the dp array.
Because you want to return an element at index "tar", for that you need a space of "tar +1"
First🔥🔥
🔥🔥🙏🙏
Done
Since both the index and sum are varying why isn't it a 2D DP concept
because the reduction is happening only in tar
Reach++
✔✔✔✔
🙏🙏
Bro oops in Java ka banao vedios
understand++
Present bhaiya
swad++
a
f
t
e
1/10 consistency++
Recursion + memoization code , Beginners friendly. hope it helps.
class Solution {
int dp[201][1001];
int f(int i, int k , vector & nums){
if( i == nums.size()) return(k ==0);
if(dp[i][k]!= -1 ) return dp[i][k];
int p =0;
int np = f(i+1 ,k,nums);
if(k>=nums[i])
p=f(0,k-nums[i],nums);
return dp[i][k] = p + np;
}
public:
int combinationSum4(vector& nums, int target) {
memset(dp,-1,sizeof(dp));
return f(0,target , nums);
}
};
This won't work though
Koi development mai course laane ka plan hai kya bhaiya.....???
Koi development mai course laane ka plan hai kya bhaiya.....???
Amazing