The Number of Beautiful Subsets leetcode || Dynamic Programming || Backtracking || Leetcode-2597

  Рет қаралды 9,720

Aryan Mittal

Aryan Mittal

Күн бұрын

Пікірлер
@ARYANMITTAL
@ARYANMITTAL Жыл бұрын
Code & Notes: leetcode.com/problems/the-number-of-beautiful-subsets/solutions/3316187/image-explanation-both-o-nlogn-o-2-n-approaches-best-explanation-on-leetcode/
@cenacr007
@cenacr007 Жыл бұрын
keep up the good work
@mayankgarg4232
@mayankgarg4232 Жыл бұрын
cool dude..really a good explanation for a beginner like me..thnx
@K_SE_SaketVerma
@K_SE_SaketVerma 8 ай бұрын
Wonderful explanation , keep up the good work !
@nkvs1248
@nkvs1248 Жыл бұрын
Oooooo Required a lot of patience , Nice one......!!!
@HandyEngineering
@HandyEngineering Жыл бұрын
nit: you do not need to sort vector v before you push items into the map mp2 (map is sorted anyway and this is why the code works)
@kashishchawla2754
@kashishchawla2754 Жыл бұрын
Can you please please make a video f question number of 1994 the number of good subsets , I am not getting the overall concept and nobody solves such tough questions on youtube except you! It would be of great help to all of us!!! Thanks!
@shabnamhaque3784
@shabnamhaque3784 21 күн бұрын
if returning 1 in base case confuses you u may try thisclass Solution { public: int dfs(vector&a,int ind,int k,unordered_map&mp){ if(ind==a.size()) return 0;//empty subset int taken=0,nottaken=0; if(mp[a[ind]-k]==0 and mp[a[ind]+k]==0) { mp[a[ind]]++; taken=1+dfs(a,ind+1,k,mp); mp[a[ind]]--; //take } nottaken=dfs(a,ind+1,k,mp); return taken+nottaken; } int beautifulSubsets(vector& nums, int k) { //make all subsets and count the good ones - brute force // make only good subsets int n=nums.size(); unordered_mapmp; int ans=dfs(nums,0,k,mp); return ans; } };
@VarunSharma-xd8xd
@VarunSharma-xd8xd 8 ай бұрын
watched 2 times but i dont know what u did in the dp approach
@cenacr007
@cenacr007 Жыл бұрын
I don't know why by map.find() wasn't working at all for me, whether I used set or map.
@bhumikanayyar2300
@bhumikanayyar2300 8 ай бұрын
why not use set in backtracking approach as we just care if nums[i]-k /nums[i]+k exists or not?
@kergeysarjakin5592
@kergeysarjakin5592 8 ай бұрын
bro 1 and 4 itself can;t be taken bcoz 4-1=3 at 7:30
@ARYANMITTAL
@ARYANMITTAL 8 ай бұрын
Yaa yaa yaa, true true bro
@killadasatyaaditya5960
@killadasatyaaditya5960 Жыл бұрын
Can you explain why prevNotTaken is inititalized with 1 and prevTaken with 0
@ARYANMITTAL
@ARYANMITTAL Жыл бұрын
As initially we have empty subset
@GauravDuseja-t6q
@GauravDuseja-t6q 8 ай бұрын
I was not able to implement backtracking proble what to do bhaiya
@ARYANMITTAL
@ARYANMITTAL 8 ай бұрын
Have you watched backtracking crash course bro?? 🫂
@Munchen888
@Munchen888 6 ай бұрын
Look. You have two options: take or not take an element. If you not take you just go further -> func(idx + 1); else take you should make a check if such element in defaultdict (dict) or not . If not you place the element in defaultdict and go further. But when you return you should remove from dict. Set in initial state .
@satvrii
@satvrii Жыл бұрын
Striver 2.0
@ArnabBhadra02
@ArnabBhadra02 8 ай бұрын
your vives match with striver
@RohitKumar-cv7qb
@RohitKumar-cv7qb Жыл бұрын
way of teaching is good, but that extra effort we require to keep attention on English, that's really irritating
@hasii36263
@hasii36263 8 ай бұрын
man this is a very bad explanation.
@prashantdubey9984
@prashantdubey9984 Жыл бұрын
Is it necessary to move your hands ?? It's really irritating
@tonytonychopper2485
@tonytonychopper2485 Жыл бұрын
"irritating" is a strong word. If you say "It would be less distracting if you reduce the hand movement", that might deliver what you wanted to say without hurting his feelings.
@ABHISHEKYADAV-lu5iz
@ABHISHEKYADAV-lu5iz 7 ай бұрын
worst explanation ever.
3085. Minimum Deletions to Make String K-Special | DP | Hash Table
16:14
"Идеальное" преступление
0:39
Кик Брейнс
Рет қаралды 1,4 МЛН
УНО Реверс в Амонг Ас : игра на выбывание
0:19
Фани Хани
Рет қаралды 1,3 МЛН
The Number of Beautiful Subsets - Leetcode 2597 - Python
32:34
NeetCodeIO
Рет қаралды 12 М.
Mastering Dynamic Programming - How to solve any interview problem (Part 1)
19:41
Sudoku problem (Hard) | Solve problems with Leetcode
33:43
Front-end Science із Сергієм Пузанковим
Рет қаралды 21 М.
2751. Robot Collisions | Stack | Sorting | Not Hard 🫡
19:30
Aryan Mittal
Рет қаралды 7 М.
5 Simple Steps for Solving Dynamic Programming Problems
21:27
Reducible
Рет қаралды 1,1 МЛН
How to Remember Everything You Read
26:12
Justin Sung
Рет қаралды 3,9 МЛН
3439. Reschedule Meetings for Maximum Free Time I | Sliding Window
15:49
Premature Optimization
12:39
CodeAesthetic
Рет қаралды 856 М.
"Идеальное" преступление
0:39
Кик Брейнс
Рет қаралды 1,4 МЛН