Million dollar wisdom : kzbin.info/www/bejne/a17Ll2iHet9oibs Backtracking Playlist: kzbin.info/aero/PLEI-q7w3s9gQtquxHpuFHXHO2OdgC0GyU
@sayantandey4708Ай бұрын
Strivers A2Z recursion done 😌😌 Thank you very much sir.
@CodeWithSunchitDudejaАй бұрын
Not try this : github.com/Sunchit/Coding-Decoded/tree/master/SDE%20Revision%20Sheet
@guptagaurav9163 жыл бұрын
Was waiting for this video. Thanks!
@stith_pragya Жыл бұрын
Thank You So Much For this wonderful video......🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻
@anujagarwal3706 Жыл бұрын
u have simply read the code. please explain recursion questions with recursive tree. Thanx.
@kouroshbaghaei3829 ай бұрын
This video was excellent! I liked your solution! 👌
@PaulFitone2 жыл бұрын
Hi @sunchit. Explanation was quiet good but you forgot to tell why you used a for loop for recursion bcoz in given examples it's not given that you can take two or more substring at once. I also thought that we only take a char at a time but this is not case so, you can modify or upload new video with mentioning those examples. Bcoz as the examples are given no can can thing of a loop just simple 3 recursive call can do job. So please include that example to understand the intuition behind for loop
@The_Promised_Neverland...2 жыл бұрын
MAYBE A BIT EASIER C++ CODE class Solution { public: void generate(string &num, int target, int curr, vector &res, string build, long long int prevNumber, long long int currSum){ if(curr==num.size()){ if(currSum==target){ res.push_back(build); } return; } for(int len=1;len1){ continue; } long long int currNum=stoll(number); generate(num,target,curr+len,res,build+"+"+number,currNum,currSum+currNum); generate(num,target,curr+len,res,build+"-"+number,-currNum,currSum-currNum); generate(num,target,curr+len,res,build+"*"+number,currNum*prevNumber,currSum-prevNumber+currNum*prevNumber); } } vector addOperators(string num, int target) { vector res; for(int len=1;len1){ continue; } long long int currNum=stoll(number); generate(num,target,len,res,number,currNum,currNum); } return res; } };
@ameynaik27433 жыл бұрын
Also for '*' the prevNum argument in DFS is prevNum*currNum... very critical!
@wintersol99213 жыл бұрын
What is the purpose of: Line 14 - > if (j > i && s.charAt(i) == '0') break; // Skip leading zero number Why do we do j > i. What happens if j == i? Can someone explain it clearly please.
@harshmantri36143 жыл бұрын
So suppose the character at ith position is 0… ex string 3012 and we are at i == 1 When we loop for j we select the substring from i to j as our current number so when j == i == 1 in this case, we are considering the current number as 0 which we can operate with. When j becomes 2 we consider 01 as the current number and 01 is not a valid two digit number so we break because any substring after the index that has 0 will have leading 0s and is not valid. Simply put, we do that thing to avoid considering substrings starting with 0. But 0 itself as a substring is fine. Thus we break for j>i and only process the ith character when the ith character is 0.
@CodeWithSunchitDudeja3 жыл бұрын
@@harshmantri3614 thanks for taking up the questions
@wintersol99213 жыл бұрын
@@harshmantri3614 Thanks a lot.
@shrimpo64162 жыл бұрын
Thx for explaining so well! I understand it right away
@anukooljaiswal86262 жыл бұрын
nice explanation..
@mrrishiraj883 жыл бұрын
Thanks
@coder10153 жыл бұрын
Bro in the dfs call of multiplication operator why are we updating the prevnum to prevnum*currnum instead of currnum pls explain
@harshmantri36143 жыл бұрын
This handles the case where we have to do consecutive multiplications… In that case, we keep track of the value of all the multiplications done so far in the prevnum, because we have to rewind the value to the last operation we did that was not a multiplication.
@manthanjoshi61103 жыл бұрын
Time complexity is 3^N right?? Where n is size of string of digits
@fardeenmeeran39093 жыл бұрын
I was under the impression that it might be (3^n * n ) since there is the for loop as well
@sushilrawat49013 жыл бұрын
Can anyone tell me multiplication case . why " -prevNum + prevNum *currNum "
@RajasthaniLadka3 жыл бұрын
On line number 14 you discard zero then how this test case :- num="00" working??
@wintersol99213 жыл бұрын
I asked the same question, there is a good explanation under my comment (someone commented a good explanation.) The simple answer is the if statement on line 14 eliminates "00" in the output. But it considers "0+0", "0-0", "0*0" because of the statement j>i. "j>i" helps to take 0 as a single number, but eliminates it from the recursion if it is a leading zero. Since 00 is the same as 0 and we don't need it in the output.
@krishnakshirsagar45702 жыл бұрын
what if / is there with +,-,*
@updates845513 күн бұрын
bss code likh ke bhaag gya\
@Coolharshit1493 жыл бұрын
Why it is break not continue in zero case ?
@rishabhpal82363 жыл бұрын
was wondering the same. Can someone explain?
@rishabhpal82363 жыл бұрын
after some thought, the zero if it comes in the middle of the string cannot exist alone as it won't change the value of resSoFar and should atleast be a two digit number.