Expression Add Operators | Leetcode 282 | Live coding session 🔥🔥🔥

preview_player
Показать описание
Here is the solution to "Expression Add Operators" leetcode question. Hope you have a great time going through it.

1) 0:00 Explaining the problem out loud
2) 1:10 Algorithm walkthrough
3) 2:00 Solution approach
4) 10:00 Coding

For discussion/feedback

PS : Please increase the speed to 1.25X

Рекомендации по теме
Комментарии
Автор

Strivers A2Z recursion done 😌😌 Thank you very much sir.

sayantandey
Автор

u have simply read the code. please explain recursion questions with recursive tree. Thanx.

anujagarwal
Автор

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

PaulFitone
Автор

Also for '*' the prevNum argument in DFS is prevNum*currNum... very critical!

ameynaik
Автор

This video was excellent! I liked your solution! 👌

kouroshbaghaei
Автор

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.

wintersol
Автор

MAYBE A BIT EASIER C++ CODE

class Solution {
public:
void generate(string &num, int target, int curr, vector<string> &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
string number=num.substr(curr, len);
if(number[0]=='0' && number.size()>1){
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<string> addOperators(string num, int target) {
vector<string> res;
for(int
string number=num.substr(0, len);
if(number[0]=='0' && number.size()>1){
continue;
}
long long int currNum=stoll(number);
generate(num, target, len, res, number, currNum, currNum);
}
return res;
}
};

The_Promised_Neverland...
Автор

Thx for explaining so well! I understand it right away

shrimpo
Автор

Bro in the dfs call of multiplication operator why are we updating the prevnum to prevnum*currnum instead of currnum pls explain

coder
Автор

On line number 14 you discard zero then how this test case :- num="00" working??

RajasthaniLadka
Автор

Time complexity is 3^N right?? Where n is size of string of digits

manthanjoshi
Автор

Can anyone tell me multiplication case . why " -prevNum + prevNum *currNum "

sushilrawat
Автор

Why it is break not continue in zero case ?

Coolharshit
welcome to shbcf.ru