- 362
- 334 806
ThinkCode
India
เข้าร่วมเมื่อ 26 เม.ย. 2020
Welcome to my channel,
I am Gaurav Kungwani from IIT(BHU) Varanasi, India passionate about coding and learning new algorithms. I try to make videoes on topics I like the most and topics which are not covered yet or not understood well by the current resources available.
I am Gaurav Kungwani from IIT(BHU) Varanasi, India passionate about coding and learning new algorithms. I try to make videoes on topics I like the most and topics which are not covered yet or not understood well by the current resources available.
Leetcode 3320 Count The Number of Winning Sequences Hindi
Leetcode 3320. Count The Number of Winning Sequences | Hindi
Leetcode 3320. Count The Number of Winning Sequences
3320 Count The Number of Winning Sequences
3320. Count The Number of Winning Sequences
Leetcode 3320. Count The Number of Winning Sequences
Leetcode contest 419
today's leetcode contest 419
Leetcode Count The Number of Winning Sequences
Count The Number of Winning Sequences leetcode
leetcode 3320 hindi
leetcode.com/problems/count-the-number-of-winning-sequences/
Leetcode contest 419
Leetcode 3320 todays leetcode contest Question
Leetcode 3320 leetcode contest
Leetcode 3320
LEETCODE CONTEST "419" CHALLENGE - VERY SIMPLE EXPLANATION with SIMPLE CODE.
Time Complexity of Incrementing the "LIKE" Variable: "LIKE++;" --- O(1)
Time Complexity of "SUBSCRIBING" to the channel: "SUBSCRIBE++;" -- O(1)
But yeah Time Complexity of Commenting is somewhat higher: O(size of comment), maybe you can reduce it by just commenting with an emoji 😉
Leetcode 3320. Count The Number of Winning Sequences
3320 Count The Number of Winning Sequences
3320. Count The Number of Winning Sequences
Leetcode 3320. Count The Number of Winning Sequences
Leetcode contest 419
today's leetcode contest 419
Leetcode Count The Number of Winning Sequences
Count The Number of Winning Sequences leetcode
leetcode 3320 hindi
leetcode.com/problems/count-the-number-of-winning-sequences/
Leetcode contest 419
Leetcode 3320 todays leetcode contest Question
Leetcode 3320 leetcode contest
Leetcode 3320
LEETCODE CONTEST "419" CHALLENGE - VERY SIMPLE EXPLANATION with SIMPLE CODE.
Time Complexity of Incrementing the "LIKE" Variable: "LIKE++;" --- O(1)
Time Complexity of "SUBSCRIBING" to the channel: "SUBSCRIBE++;" -- O(1)
But yeah Time Complexity of Commenting is somewhat higher: O(size of comment), maybe you can reduce it by just commenting with an emoji 😉
มุมมอง: 230
วีดีโอ
Leetcode 3306 Count of Substrings Containing Every Vowel and K Consonants II - Hindi
มุมมอง 73121 วันที่ผ่านมา
Leetcode 3306. Count of Substrings Containing Every Vowel and K Consonants II | Hindi Leetcode 3306. Count of Substrings Containing Every Vowel and K Consonants II 3306 Count of Substrings Containing Every Vowel and K Consonants II 3306. Count of Substrings Containing Every Vowel and K Consonants II Leetcode 3306. Count of Substrings Containing Every Vowel and K Consonants II Leetcode contest 4...
Leetcode 3305 Count of Substrings Containing Every Vowel and K Consonants I
มุมมอง 22221 วันที่ผ่านมา
Brute force to check every substring, explained the thought process in easy manner in Hindi Count of Substrings Containing Every Vowel and K Consonants I | Hindi Leetcode 3305. Count of Substrings Containing Every Vowel and K Consonants I 3305 Count of Substrings Containing Every Vowel and K Consonants I 3305. Count of Substrings Containing Every Vowel and K Consonants I Leetcode 3296. Minimum ...
Leetcode 3296 Minimum Number of Seconds to Make Mountain Height Zero | Binary Search | Hindi
มุมมอง 1.6Kหลายเดือนก่อน
Binary Searched two times, explained the thought process in easy manner in Hindi Minimum Number of Seconds to Make Mountain Height Zero | Hindi Leetcode 3282. Minimum Number of Seconds to Make Mountain Height Zero 3296 Minimum Number of Seconds to Make Mountain Height Zero 3296. Minimum Number of Seconds to Make Mountain Height Zero Leetcode 3296. Minimum Number of Seconds to Make Mountain Heig...
Leetcode 3282 Reach End of Array With Max Score Hindi
มุมมอง 263หลายเดือนก่อน
Simple Greedy, explained the thought process in easy manner in Hindi Reach End of Array With Max Score | Hindi Leetcode 3282. Reach End of Array With Max Score 3282 Reach End of Array With Max Score 3282. Reach End of Array With Max Score Leetcode 3282. Reach End of Array With Max Score Leetcode contest 414 today's leetcode contest 414 Leetcode Reach End of Array With Max Score Reach End of Arr...
Leetcode 3281 Maximize Score of Numbers in Ranges
มุมมอง 852หลายเดือนก่อน
Using binary search on answer , explained the thought process in easy manner in Hindi Maximize Score of Numbers in Ranges | Hindi Leetcode 3281. Maximize Score of Numbers in Ranges 3281 Maximize Score of Numbers in Ranges 3281. Maximize Score of Numbers in Ranges Leetcode 3281. Maximize Score of Numbers in Ranges Leetcode contest 414 today's leetcode contest 414 Leetcode Maximize Score of Numbe...
Leetcode 3259. Maximum Energy Boost From Two Drinks Hindi
มุมมอง 1602 หลายเดือนก่อน
Using recursion memo, explained the thought process in easy manner in Hindi Maximum Energy Boost From Two Drinks | Hindi Leetcode 3259. Maximum Energy Boost From Two Drinks 3259 Maximum Energy Boost From Two Drinks 3259. Maximum Energy Boost From Two Drinks Leetcode 3259. Maximum Energy Boost From Two Drinks Leetcode contest 411 today's leetcode contest 411 Leetcode Maximum Energy Boost From Tw...
Komal Kungwani SDE2 @Microsoft organising a happiness workshop on how to crack interviews. Register!
มุมมอง 1943 หลายเดือนก่อน
“𝐇𝐚𝐩𝐩𝐲 𝐒𝐭𝐮𝐝𝐞𝐧𝐭𝐬 = 𝐒𝐮𝐜𝐜𝐞𝐬𝐬𝐟𝐮𝐥 𝐒𝐭𝐮𝐝𝐞𝐧𝐭𝐬! 🎉 Join me, 𝐊𝐨𝐦𝐚𝐥, on July 6th, as I share secrets and tricks to crack any Interview. 🤩 - Develop a 𝐩𝐨𝐬𝐢𝐭𝐢𝐯𝐞 𝐦𝐢𝐧𝐝𝐬𝐞𝐭 that will help you crush any challenge 💡 - Build resilience and 𝐜𝐨𝐧𝐟𝐢𝐝𝐞𝐧𝐜𝐞 that will make you unstoppable 💪 - Learn to 𝐬𝐦𝐢𝐥𝐞 𝐭𝐡𝐫𝐨𝐮𝐠𝐡 𝐜𝐡𝐚𝐥𝐥𝐞𝐧𝐠𝐞𝐬 and come out stronger on the other side 🌈 - 𝐀𝐜𝐡𝐢𝐞𝐯𝐞 𝐘𝐨𝐮𝐫 𝐀𝐢𝐦𝐬 ! 🎉 This session is NOT just about p...
Leetcode Maximize Total Cost of Alternating Subarrays Hindi
มุมมอง 1464 หลายเดือนก่อน
Using recursion memo, explained the thought process in easy manner in Hindi Maximize Total Cost of Alternating Subarrays | Hindi Leetcode 3196. Maximize Total Cost of Alternating Subarrays 3196.Maximize Total Cost of Alternating Subarrays 3196. Maximize Total Cost of Alternating Subarrays Leetcode 3196. Maximum Total Damage With Spell Casting Leetcode contest 403 today's leetcode contest 403 Le...
Leetcode Maximum Total Damage With Spell Casting | Recursion + Memo
มุมมอง 2004 หลายเดือนก่อน
Using recursion memo, explained the thought process in easy manner in Hindi 3186. Maximum Total Damage With Spell Casting | Hindi Leetcode 3186. Maximum Total Damage With Spell Casting 3186.Maximum Total Damage With Spell Casting 3186. Maximum Total Damage With Spell Casting Leetcode 3186. Maximum Total Damage With Spell Casting Leetcode contest 402 today's leetcode contest 402 Leetcode Maximum...
Leetcode 3043. Find the Length of the Longest Common Prefix Hindi
มุมมอง 2628 หลายเดือนก่อน
Simpel Trie Very Simple Explanation, explained in easy manner in Hindi 3043. Find the Length of the Longest Common Prefix | Hindi Leetcode 3043. Find the Length of the Longest Common Prefix 3043. Find the Length of the Longest Common Prefix 3044. Most Frequent Prime Leetcode 3043. Find the Length of the Longest Common Prefix Leetcode contest 385 today's leetcode contest 385 Leetcode Most Freque...
Leetcode 3044. Most Frequent Prime TLE? Hindi
มุมมอง 2588 หลายเดือนก่อน
TLE ? Very Simple Explanation, explained in easy manner in Hindi 3044. Most Frequent Prime | Hindi Leetcode 3044. Most Frequent Prime 3044. Most Frequent Prime 3044. Most Frequent Prime Leetcode 3044. Most Frequent Prime Leetcode contest 385 today's leetcode contest 385 Leetcode Most Frequent Prime Most Frequent Prime leetcode leetcode 3044 hindi leetcode.com/problems/most-frequent-prime/ Leetc...
Leetcode 1642. Furthest Building You Can Reach Hindi
มุมมอง 858 หลายเดือนก่อน
Intuitive and Easy Explanation, explained in easy manner in Hindi 1642. Furthest Building You Can Reach | Hindi Leetcode 1642. Furthest Building You Can Reach 1642. Furthest Building You Can Reach Furthest Building You Can Reach Leetcode 1642. Furthest Building You Can Reach today's leetcode challenge Leetcode Furthest Building You Can Reach Furthest Building You Can Reach leetcode leetcode 164...
Leetcode 1481. Least Number of Unique Integers after K Removals Hindi
มุมมอง 638 หลายเดือนก่อน
Intuitive and Easy Explanation, explained in easy manner in Hindi 1481 Least Number of Unique Integers after K Removals | Hindi Leetcode 1481 Least Number of Unique Integers after K Removals 1481. Least Number of Unique Integers after K Removals Least Number of Unique Integers after K Removals Leetcode 1481. Least Number of Unique Integers after K Removals today's leetcode challenge Leetcode Le...
Built Simple Splitwise in js | Live Coding from Scratch 🔥🔥 | Low Level Design | Part 1
มุมมอง 1319 หลายเดือนก่อน
Built Simple Splitwise in js | Live Coding from Scratch 🔥🔥 | Low Level Design | Part 1
Leetcode 2147 Number of Ways to Divide a Long Corridor
มุมมอง 11810 หลายเดือนก่อน
Leetcode 2147 Number of Ways to Divide a Long Corridor
Leetcode 741 Cherry Pickup - Intuitive And Easy - Hindi
มุมมอง 1.3K11 หลายเดือนก่อน
Leetcode 741 Cherry Pickup - Intuitive And Easy - Hindi
Leetcode 1877 Minimize Maximum Pair Sum in Array
มุมมอง 12711 หลายเดือนก่อน
Leetcode 1877 Minimize Maximum Pair Sum in Array
Leetcode 2905 Find Indices With Index and Value Difference II
มุมมอง 783ปีที่แล้ว
Leetcode 2905 Find Indices With Index and Value Difference II
Leetcode 2896 Apply Operations to Make Two Strings Equal
มุมมอง 2.2Kปีที่แล้ว
Leetcode 2896 Apply Operations to Make Two Strings Equal
Leetcode 1282 Group the People Given the Group Size They Belong To
มุมมอง 331ปีที่แล้ว
Leetcode 1282 Group the People Given the Group Size They Belong To
Leetcode 2849 Determine if a Cell Is Reachable at a Given Time Hindi
มุมมอง 444ปีที่แล้ว
Leetcode 2849 Determine if a Cell Is Reachable at a Given Time Hindi
Leetcode 2844 Minimum Operations to Make a Special Number Hindi
มุมมอง 770ปีที่แล้ว
Leetcode 2844 Minimum Operations to Make a Special Number Hindi
Leetcode 459 Repeated Substring Pattern + TIME COMPLEXITY IN DEPTH + Hindi
มุมมอง 188ปีที่แล้ว
Leetcode 459 Repeated Substring Pattern TIME COMPLEXITY IN DEPTH Hindi
Leetcode 2831 Find the Longest Equal Subarray | Hindi
มุมมอง 1.1Kปีที่แล้ว
Leetcode 2831 Find the Longest Equal Subarray | Hindi
Leetcode 2828 Check if a String Is an Acronym of Words Hindi
มุมมอง 413ปีที่แล้ว
Leetcode 2828 Check if a String Is an Acronym of Words Hindi
Leetcode 2830 Maximize the Profit as the Salesman Hindi
มุมมอง 1.6Kปีที่แล้ว
Leetcode 2830 Maximize the Profit as the Salesman Hindi
Will sum>0 always? I doubt. If sum becomes negative then we cannot use dp array
yes bro thats why sum>1000 not sum>0 to encounter negative values in dp, so basically sum=0 is represented as sum=1000, and sum=-1 is represented as sum=-999 and so on...
since the size is 1000, the worst sum could be -1000, and -1000 is represented as 0. so we just add 1000 to each value whether negative or positive.
bhai solution ka link bhi attatch kr diya kro, Nice explanation👍👍
upar hai toh code 😅
Like, Subscribe, Comment. Code: class Solution { public: int mod; long long solve(string &s, int index, vector<vector<vector<int> > > &dp, int sum, int w){ if(index==s.size()){ if(sum>s.size()){ return 1; } else{ return 0; } } if(dp[index][sum][w]!=-1){ return dp[index][sum][w]%mod; } if(w==0){ if(s[index]=='F'){ return dp[index][sum][w]=(solve(s,index+1,dp,sum, 1)%mod+solve(s,index+1,dp,sum+1, 2)%mod + solve(s,index+1,dp,sum-1, 3)%mod)%mod; } else if(s[index]=='W'){ return dp[index][sum][w]=(solve(s,index+1,dp,sum, 2)%mod+solve(s,index+1,dp,sum-1, 1)%mod + solve(s,index+1,dp,sum+1, 3)%mod)%mod; } else if(s[index]=='E'){ return dp[index][sum][w]=(solve(s,index+1,dp,sum, 3)%mod+solve(s,index+1,dp,sum-1, 2)%mod + solve(s,index+1,dp,sum+1, 1)%mod)%mod; } } else if(w==1){ if(s[index]=='F'){ return dp[index][sum][w]=(solve(s,index+1,dp,sum+1, 2) %mod+ solve(s,index+1,dp,sum-1, 3)%mod)%mod; } else if(s[index]=='W'){ return dp[index][sum][w]=(solve(s,index+1,dp,sum, 2)%mod+ solve(s,index+1,dp,sum+1, 3)%mod)%mod; } else if(s[index]=='E'){ return dp[index][sum][w]=(solve(s,index+1,dp,sum, 3)%mod+solve(s,index+1,dp,sum-1, 2)%mod )%mod; } } else if(w==2){ if(s[index]=='F'){ return dp[index][sum][w]=(solve(s,index+1,dp,sum, 1)%mod+ solve(s,index+1,dp,sum-1, 3)%mod)%mod; } else if(s[index]=='W'){ return dp[index][sum][w]=(solve(s,index+1,dp,sum-1, 1)%mod + solve(s,index+1,dp,sum+1, 3)%mod)%mod; } else if(s[index]=='E'){ return dp[index][sum][w]=(solve(s,index+1,dp,sum, 3)%mod+solve(s,index+1,dp,sum+1, 1)%mod)%mod; } } else{ if(s[index]=='F'){ return dp[index][sum][w]=(solve(s,index+1,dp,sum, 1)%mod+solve(s,index+1,dp,sum+1, 2)%mod )%mod; } else if(s[index]=='W'){ return dp[index][sum][w]=(solve(s,index+1,dp,sum, 2)%mod+solve(s,index+1,dp,sum-1, 1)%mod )%mod; } else if(s[index]=='E'){ return dp[index][sum][w]=(solve(s,index+1,dp,sum-1, 2)%mod + solve(s,index+1,dp,sum+1, 1)%mod)%mod; } } return 0; } int countWinningSequences(string s) { // vector<vector<int>> dp(s.size(),vector<int>(2001,-1)); mod=pow(10,9)+7; int n=s.size(); vector<vector<vector<int> > > dp( n, vector<vector<int> >(2*n+1, vector<int>(4,-1))); return solve(s,0 , dp, n, 0); } };
Superb man thanks
welcome !!!
Amazing explanation. I also solved this question using a sliding window but couldn't figure out during the contest that if we find a substring with ≥ k consonants and subtract the substring with ≥ k+1 consonants, we can get the substring with exactly k consonants. I learned something new and won't forget this now. Thank you so much for making amazing videos. How do you figure out these tricks? I also want to learn them.
Actually it was tricky, I couldn't figure it out during contest, I read discussion posts.
Thanks 🙏
welcome !! 😄
bhai sbb kuchh to shi h bss ek doubt h clear krdo, ans += word.size() - j; means we are assuming agr hmme 0 to j tk condition satisfy ho gyi to baaki bache substring me bhi ho jaeggi but catche ye h ki hmme exactly k constant chahiye then how we can assume baki ke word.size() - j substring me k constant honge k se jyada hue to ?
yes buddy you understood it correctly, we are finding for >=k and then we will use same function to calculate for >=k+1 so to find for exactly k, we need to subtract them.
@@Think_Code i got it thanks bro
" i " is the left pointer and " j " is right pointer, we will increment j till the point we are not satisfying our condition of having all vowels and k consonants and when the condition is satisfied we will increment i pointer ( which is left pointer ) till we are still satisfying the condition. Like, Subscribe, Comment if you have doubts. Subscribe !! class Solution { public: long long solve(string word, int k){ int i=0; int j=0; long long ans=0; map<char,int> mp; int cnt=0; while(j<word.size()){ if(word[j]=='a' || word[j]=='e' || word[j]=='i' || word[j]=='o' || word[j]=='u'){ mp[word[j]]++; } else{ cnt++; } // while(mp.size()==5 && cnt>=k){ ans+=word.size()-j; if(mp.find(word[i])!=mp.end()){ mp[word[i]]--; if(mp[word[i]]==0){ mp.erase(word[i]); } } else{ cnt--; } i++; } j++; } return ans; } long long countOfSubstrings(string word, int k) { return solve(word, k) - solve(word,k+1); // Leetcode Count of Substrings Containing Every Vowel and K Consonants II } };
Thanks buddy
welcome!!
Like, Subscribe, Comment. Subscribe !! Code: class Solution { public: int countOfSubstrings(string word, int k) { // a e i o u int ans=0; for(int i=0;i<word.size();i++){ int a=0,e=0,p=0,o=0,u=0,c=0; for(int j=i;j<word.size();j++){ if(word[j]=='a'){ a++; } else if(word[j]=='e'){ e++; } else if(word[j]=='i'){ p++; } else if(word[j]=='o'){ o++; } else if(word[j]=='u'){ u++; } else { c++; } if(a>0 && e>0 && p>0 && o>0 && u >0 && c==k){ ans++; } } } return ans; } };
bhai tu 8 min tak output ko hi leke chal raha hai logic toh taab pata chlalega na jab output aaya kaise woh baatega tu output ho hi justify kar raha hai ye baatana ki output aaise aaya
First of all, dont use casual language.
@@Think_Code you're stuck on the output for 8 minutes straight. You'll only understand the logic once you explain how the output came about. You're justifying the output itself without explaining how it was generated. is this better?
@@lunagok7395 Because output we get by binary searching over it. I thought first to explain how you check the correctness of a `assumed answer`. Then i explained we will run a binary search over all the possible answers and check if the assumed answer is possible or not.
in the later part, mostly in the last part i have told how we will choose l and r to binary search over all possible answers.
i would suggest you to solve how to find sqrt of a number. In which we run a binary search from 1 to n and check if the mid value is answer or not by checking mid*mid==n.
Saw a lot of videos overcomplicating this. simplest solution there is.
Thanks !!
Very clear and amazing explanation. I figured out the first binary search since it’s a max-min type of question, but I couldn’t figure out the second one in the contest. But now its all clear. I’ll be looking forward to your video for the other weekly contest questions as well!
Thanks !! Sure! 😄
Thanks
thanks for commentating, it really means a lot.
badhiya
thanks !! 😃
nhi samaj aya ,mere pas dimag nhi hai🤧🤧
Ye aisa question hai ki khud se karo toh hi ache se samaj aaega. Ek binary tak toh theek hai, but dusra binary search lagta hai how would i solve.
Like , Subscribe, Comment. Don't forget to SUBSCRIBE !! Code : class Solution { public: int cal(int val, vector<long long > &pre, long long x){ long long l=0; long long r=pre.size()-1; int ans=-1; while(l<=r){ long long mid=l+(r-l)/2; if(pre[mid]*(long long )val<=x){ ans=mid; l=mid+1; } else{ r=mid-1; } } return ans; } bool check(int m, vector<int> &w, long long x,vector<long long > &pre){ // [2,1,1] //ith worker ne kitni h reduce kari x sec // 2,[1,3,6,10,,] // 2,6,12,12,.. // ans = 3 sec possible hai ? for(int i=0;i<w.size();i++){ int p=cal(w[i],pre,x); if(p!=-1){ m-=(p+1); } } if(m<=0){ return true; } return false; } long long minNumberOfSeconds(int m, vector<int>& w) { long long o=(long long )m*(long long )(m+1)/2; long long u=*max_element(w.begin(),w.end()); long long r=o*u; long long l=0; long long ans=pow(10,16); vector<long long > pre; pre.push_back(1); long long t=2; while(1){ if(pre.size()>m){ break; } pre.push_back(pre[pre.size()-1]+t); t++; } // pre = [1,3,6,10,15,21,...] while(l<=r){ long long mid=l+(r-l)/2; if(check(m,w,mid,pre)){ ans=mid; r=mid-1; } else{ l=mid+1; } } return ans; } };
Thank you, it would be really hard to come up with this on my own unless I ran through a lot of patterns
With Practice, it would be easy. Also some problems click you, sometimes they don't.
Didi what was your CGPA?
all testcases are passing but you do not perform bitwise AND, why??
because performing the bitwise AND will only reduce the value, so we just have to take maximum element and count its continuous occurence.
@@Think_Code But the same logic is not correct for bitwise OR operation
@@VIVEKKUMAR-xs9zp might be, but it Is AND here not OR.
bro one question is sorting the given array wont effect the absolute difference of orignal array
yes it will not effect. How it will ? You only have to choose elements from the array, doesn't matter the order.
@@Think_Code thank you bro
Can you please explain, why you took low as 0 for starting condition of Binary Search. Suppose you have array: [0, 4, 8] and d=1. Here the minimum valid difference shouldn't be: 4 I have doubt for this not being Monotonic in this way.
yes in that case you can calculate the low value as i have calculated the high value.
thank you for mentioning my channel 😊😊
W E L C O M E !! 😄
The best video I found for this question. Huge shoutout!
T H A N K S !! 😄
not able to solve in contest 😭😭
Koi na !! Next time 👊
Thanks
welcome!!
nice bro keep posting
Like! SUBSCRIBE! Comment! Below is the code : Code : class Solution { public: long long findMaximumScore(vector<int>& nums) { long long ans=0; int curr=nums[0]; int j=0; for(int i=1;i<nums.size();i++){ if(nums[i]>curr){ ans+=(long long )curr*(long long )(i-j); curr=nums[i]; j=i; } } if(j!=nums.size()-1){ ans+=(long long )curr*(long long )(nums.size()-1-j); } return ans; } };
Like! SUBSCRIBE! Comment! Below is the code : Code : class Solution { public: bool check(long long x, vector<long long> &start, int d){ long long curr=start[0]; for(int i=1;i<start.size();i++){ if(start[i]>curr+(long long )x){ curr=start[i]; } else if(curr+(long long)x <= (long long )start[i]+(long long )d){ curr = curr+x; } else{ return 0; } } return 1; } int maxPossibleScore(vector<int>& s, int d) { vector<long long > start; for(int i=0;i<s.size();i++){ start.push_back((long long )s[i]); } sort(start.begin(),start.end()); int l=0; int r=d+start[start.size()-1]-start[0]; int ans=0; while(l<=r){ long long mid=l+(r-l)/2; if(check(mid,start,d)){ ans=mid; l=mid+1; } else{ r=mid-1; } } return ans; } };
Nice Explanation bro👊
thanks
cant we have visited array rather than using masking?
how will you store that in the dp array? you can make a dp array of dp[ u ] [ mask ], since mask is just an integer
I wrote recursive code for this same as house robber. Thanks
good video. Friendly feedback: the voice volume is low. I had to plug in my headphones. Had a question, in such dp questions, how do you first find the overlapping subproblems though? Maine input ke sath try kiya tha and also with some test cases i made up. i still couldn't find any overlaps at all. Har baar alag alag test cases ke trees banane padhenge ya we just wing it with the dp cache and hope there are overlaps? Contest mai kaise solve karen is type ke dp questions? Mujhe laga ye dp question hoga hi nahi kyunki i didnt any overlaps, i wasted 1 hour 15 mins of my contesst time trying to solve it with greedy. i got pretty close (502/563) test cases passed and it took me until today to figure out why greedy won't work. How do I improve at this?
dekho aisa hota hai, ki 2-3 bar tumhe dekhna padega ki overlap hai ki nahi, phir muscle memory se khud hi dikh jata hai ki hain overlap hai. Vahi tree banake dekhna padega ki subproblems repeat ho rahi hai. Greedy ke liye ek-2 test case khud sochne padenge jinpe run nahi karega. Bahut simply mil jate hai, jaise [1,3,2] [3,1,1] hota agar toh 3 lete second array se phir agar upar wale array me jaoge. toh ek leave karna padega phir 2 le loge greedy se but answer 6 hoga not 5.
Efforts 👍🏻👍🏻
thanks!
Excellentttttt
thanks !!
Thank youuuuuuu
Welcome!
thanks mere sindhi bhai
thanks bhai !!
Best explanation 👍
thanks !! 😄
Perfect ❤
thanks !!
class Solution { public: void order(vector<pair<long long, long long>>& vec) { int n = vec.size(); for (auto& it : vec) { it.second = (it.second + (n - 1)) % n; } } long long minCost(vector<int>& nums, int x) { vector<pair<long long, long long>> vec; int n = nums.size(); for (long long i = 0; i < n; i++) { vec.push_back({nums[i], i}); } vector<long long> ans; for (auto& it : vec) { ans.push_back(it.first); } long long minm = accumulate(ans.begin(), ans.end(), 0ll); for (long long op = 1; op < n; op++) { order(vec); long long result = 0; for (int i = 0; i < n; i++) { long long val = vec[i].first; long long idx = vec[i].second; if (ans[idx] > val) { result += val; ans[idx] = val; } else { result += ans[idx]; } } result += (long long)(op * x); minm = min(result, minm); } return minm; } };
You'll get MLE on this solution
i didnt got
Amazing explaination
thanks !!😃
Good explanation sir.
thanks !! 😄
👎👎👎
so smooth bro,nicely done😁😁😁
thanks !!😄
bhai video ekdum bdia hai par voice mai thoda issue tha difficulty horhi ha samajhne mai thodi
@@mukulkhanna5071 haan dikkat toh hai 😓😓
Great
thanks !! 😄
no need to use max in first and third if, btw good solution
what is rans
i guess its not getting used, so you can ignore
Subscribe !! Like !! Comment !! Code : class Solution { public: long long solve(vector<int> &nums, vector<vector<long long >> &dp, int index, int choice){ if(index==nums.size()){ return 0; } if(dp[index][choice]!=INT_MIN){ return dp[index][choice]; } if(choice==0){ return (long long )nums[index]+solve(nums, dp, index+1, 1); } long long newS= (long long )nums[index]+solve(nums, dp, index+1, 1); long long cont = (long long )(-nums[index])+solve(nums, dp, index+1, 0); return dp[index][choice] = max(newS,cont); } long long maximumTotalCost(vector<int>& nums) { vector<vector<long long >> dp(nums.size(),vector<long long > (2,INT_MIN)); return solve(nums, dp, 0, 0); } };