2920. Maximum Points After Collecting Coins From All Nodes | Weekly Leetcode 369

  Рет қаралды 872

codingMohan

codingMohan

Күн бұрын

Пікірлер: 19
@mukultaneja7243
@mukultaneja7243 Жыл бұрын
Hi Mohan. Thanks for such a great explanation. Can you please confirm if 1. Dividing a positive number by 2^n, and 2. Dividing a number by 2 "n times" same or different here?
@codingmohan
@codingmohan Жыл бұрын
Initially I thought it was different but I think they are same here.
@mukultaneja7243
@mukultaneja7243 Жыл бұрын
@@codingmohan Yes I also verified, they are the same. So we can optimize our code further to O(N*B), I believe.
@codingmohan
@codingmohan Жыл бұрын
@@mukultaneja7243 Yes we can.
@smitrajrana4016
@smitrajrana4016 Жыл бұрын
@mukultaneja7243 @codingmohan is it always the case or particularly for this problem both operations are same?
@codingmohan
@codingmohan Жыл бұрын
​@@smitrajrana4016 Thanks for asking. I think this is always be the case and not something to do with "2" here. Intuition - Let's say you are dividing by 2 i.e. you want to verify whether floor(N/2^X) == floor(floor(N/2)/2)... You can write N in base 2 here and you will have something like "1101.....". Here dividing by 2 and taking floor simply mean removing the last bit. Therefore if you divide further by 2, it means you are simply truncating the last 2 bits. And so on ... Further, if you divide N by 2^X, it means you are still truncating the last X bits but as it is not "floor", you will have (last X bit value)/2^X which is "always" a decimal number. And hence if you take a floor of overall, it will come as same value as the above. Replace "2" with any number of your choice and everything will still holds. Therefore, it will always be the case. A simple simulation - ideone.com/TJs2OK Let me know if you want me to create a short video on this :)
@devenderbhatt421
@devenderbhatt421 Жыл бұрын
Nice approach to explain even someone new to these problems ty❤
@sujalsingh7675
@sujalsingh7675 Жыл бұрын
Amazing solution
@ani68
@ani68 Жыл бұрын
At 36:50 can you please help me understand how the value of sumation Child = 2N And how does 2N is equal to the number of edges
@codingmohan
@codingmohan Жыл бұрын
This is a tree which means there will be (N-1) edges. For each node we are visiting all it's neighbors. Therefore, each edge will be used twice - let's say there is an edge a --> b, then we will visit this edge when we will be at node "a" and we will visit this edge again when we will be at node "b".
@ani68
@ani68 Жыл бұрын
@@codingmohan oh yeah... got it... thanks 😊
@ayushanand18
@ayushanand18 Жыл бұрын
after each contest, the next day I come over for upsolving. and if I do not get it within the first 40 mins, I always search the last question on your youtube. I go down until your video is there - and this is what i wait for! amazing explanation, in-depth and growth oriented. full of learning! thanks man!
@devenderbhatt421
@devenderbhatt421 Жыл бұрын
At line 13 shouldn't it be zero instead of -inf?
@AmanSingh-on4ce
@AmanSingh-on4ce Жыл бұрын
No need to run a loop to find, value of V after by_2 no of divisions. int dfs(int node,int par,int p) { if(dp[node][p]!=-1) return dp[node][p]; if(p>14) return 0; int cur = coins[node]/(1
@RAUSHANKUMAR-gw9ri
@RAUSHANKUMAR-gw9ri Жыл бұрын
Hii mohan, the time complexity for brute force recursion is some what 2^n since we are calling at each index two possibilities?
@devenderbhatt421
@devenderbhatt421 Жыл бұрын
U mean without dp?
@we_atheletes
@we_atheletes Жыл бұрын
Superb Bhaiii
@divyanshuagarwal1912
@divyanshuagarwal1912 Жыл бұрын
Nice
The evil clown plays a prank on the angel
00:39
超人夫妇
Рет қаралды 53 МЛН
人是不能做到吗?#火影忍者 #家人  #佐助
00:20
火影忍者一家
Рет қаралды 20 МЛН
Une nouvelle voiture pour Noël 🥹
00:28
Nicocapone
Рет қаралды 9 МЛН
L28. Maximum Width of Binary Tree | C++ | Java
22:41
take U forward
Рет қаралды 293 М.
Minimum Cost Good Caption (Leetcode Biweekly 149)
14:44
Soumya Bhattacharjee
Рет қаралды 170
one year of studying (it was a mistake)
12:51
Jeffrey Codes
Рет қаралды 316 М.
AI Is Making You An Illiterate Programmer
27:22
ThePrimeTime
Рет қаралды 276 М.
5 Simple Steps for Solving Dynamic Programming Problems
21:27
Reducible
Рет қаралды 1,1 МЛН
3250. Find the Count of Monotonic Pairs I | Weekly Leetcode 410
20:00
3225. Maximum Score From Grid Operations | Leetcode Biweekly 135
1:04:57
The evil clown plays a prank on the angel
00:39
超人夫妇
Рет қаралды 53 МЛН