BASIC CALCULATOR II | LEETCODE 227 | PYTHON SOLUTION

  Рет қаралды 20,245

Cracking FAANG

Cracking FAANG

Күн бұрын

Пікірлер: 43
@yuqian822
@yuqian822 9 ай бұрын
Awesome solution! This is much easier to understand and remember than the stack solution. I went with the stack solution before but I always missed some details or forgot certain lines of code every time I reviewed this problem... I hope this solution is acceptable by the interviewer. (I wouldn't be that picky if I am an interviewer but who knows). Thanks again!
@crackfaang
@crackfaang 9 ай бұрын
No problem! Glad you found the video helpful and the solution was intuitive for you
@johnangelo2000
@johnangelo2000 9 ай бұрын
This made me think how can one ask brain to observe operation without complicating them. This is awesome... I couldn't do it first with this clarity.. Thanks a bunch for clear thought..
@pat777b
@pat777b 4 ай бұрын
For the int(pre / cur) vs pre // curr, I think i would ask the interviewer a clarifying question about how they want integer division to behave first. I'd just go in the direction they suggest me to. If they want to truncate to zero as the leetcode problem does, then i would go with int(pre / cur) as you suggest. I'd adjust appropriately depending on what the interviewer wants. I got to ask these clarifying questions cause sometimes the interviewers do twists. Nice solution btw.
@kalyanvejalla
@kalyanvejalla 15 күн бұрын
This solution fails for the test case "14-3/2". Yours returns 12 when the expected is 13. I had to do int(float(prev) / current) for division instead
@Ankit-hs9nb
@Ankit-hs9nb 2 жыл бұрын
5:27 I think a small correction, the previous number is 2 not 3
@zuccca
@zuccca 8 ай бұрын
This channel is nothing short of pure gold. I am preparing for FAANG interviews currently. Do you offer any kind of 1-on-1 coaching? Please let me know!
@crackfaang
@crackfaang 8 ай бұрын
Hey thanks for the very kind words. I do actually! If you join as a channel member at the $50/month tier you get 1 mock interview per month and at the $100 tier you get 2 per month + the perks of the lower tiers like resume review, private Q&A group with me, etc. You can check it out on my channel page by clicking the "Join" button to see the options. You can cancel it after your interviews when you no longer need it of course :)
@hooriehmarefat5972
@hooriehmarefat5972 2 жыл бұрын
Nice solution! Thanks. As a suggestion, if you can make the code page clearer, that would be awesome because the code page is very blurry and not easy to see.
@elikiperwasser
@elikiperwasser 2 ай бұрын
What about multiple multiplications like 2*3*4? The code you wrote will try to undo a summation but there isn't one..
@TheAdityabhandari
@TheAdityabhandari 2 жыл бұрын
If you're not using python3, the solution only gets accepted if you convert the res in the division to int(float(prev)/cur)
@crackfaang
@crackfaang 2 жыл бұрын
I mean this is a solution in Python 3 so it’s not guaranteed to work line by line in other languages
@n6i9k4a
@n6i9k4a Жыл бұрын
​@@crackfaang in LC, there's still a distinction between Python and Python3 in the language selection, so if you try to submit this solution in "Python" vs "Python3", it won't pass all test cases without this modification. I didn't catch that at first and couldn't figure out why this solution wouldn't pass all the test cases. Thanks @TheAdityabhandari
@crackfaang
@crackfaang Жыл бұрын
​@@n6i9k4a You should not be using anything except Python3. The other version of Python is for some reason still allowed despite Python2 being deprecated on January 1, 2020. All solutions are always for Python3
@akshaychavan5511
@akshaychavan5511 6 ай бұрын
You should just take the floor value of the division without complicating things.
@vishnuteja9758
@vishnuteja9758 18 күн бұрын
For division, if you want to truncate to 0, in python3 we would have to use int(float(prev) / curr)
@yingxu1694
@yingxu1694 6 күн бұрын
always do res -= prev when encountering * and /, what if the previous operation is -
@ye7841
@ye7841 2 жыл бұрын
Great solution! Much easier to understand for a beginner ;) just wondering if there is a way to get rid of the i-=1 ? I think I would probably miss it if I got nervous in a real interview.
@crackfaang
@crackfaang 2 жыл бұрын
Yea you could just check that while s[i+1].isdigit() for the while loop instead. That would stop the iteration at the last digit you need to parse. I learned it the other way and that's what has stuck in my brain. Whatever works for you is best :)
@ye7841
@ye7841 2 жыл бұрын
@@crackfaang I need some help here: if using s[i+1].isdigit() then the last digit would not be added, right? e.g. 123+4*5, the 3 would not be added as the next char is not a digit...did I miss something here? Thank you so much!
@wayne4591
@wayne4591 Жыл бұрын
Really good explanation! Thanks! The idea of undo the previous operation the really good as well as the set prev = prev * cur one.
@dnm9931
@dnm9931 2 ай бұрын
Thank you soo much! You are appreciated!
@darleisoares23
@darleisoares23 2 жыл бұрын
Great video, keep those coming, nice job
@crackfaang
@crackfaang 2 жыл бұрын
Thanks for the support! Make sure to subscribe so you don’t miss future videos
@symbol767
@symbol767 2 жыл бұрын
Took me a while and I had to learn the stack solution first, I suggest everyone learn the stack solution because you can solve all 3 calculator problems with it, but after learning the stack solution I came back here and understood your solution much better. Then I managed to solve Calculator 1 and 3 on my own right after, the stack solution for Calculator 1 worked perfectly for Calculator 3 loll
@crackfaang
@crackfaang 2 жыл бұрын
Yea the stack solution is quite simple but the interview is basically always going to want the O(1) solution lol
@daxtermaster6793
@daxtermaster6793 8 ай бұрын
Thanks, it's true, it becomes intuitive when we understand first the stack solution.
@kapilrules
@kapilrules 26 күн бұрын
how did you assumed that curr_operation will always start with +? what if start with other operator?
@Andrew-dd2vf
@Andrew-dd2vf 26 күн бұрын
It's because the first number we encounter is always "added" to the total sum "res", initialized to 0. Let's consider an edge case of one number, say s = [2]. we know that the result should be 2, and you can think of it as 0 + 2 (where 0 is the previous number and + is curr_operation). If you used " * ", the result for this case would be 0 (since 0 * 2), which we know is clearly false
@bellicose100x
@bellicose100x Жыл бұрын
great explanation of the intuition and solution.
@sarayarmohammadi3376
@sarayarmohammadi3376 8 сағат бұрын
Thank you
@devinenivenkatesh6101
@devinenivenkatesh6101 Жыл бұрын
Thanks you sir Nice solutions
@crackfaang
@crackfaang Жыл бұрын
No problem glad you liked the video
@roywastaken
@roywastaken Жыл бұрын
GOAT solution... i used a stack lol
@AmolGautam
@AmolGautam 10 ай бұрын
Thank you so much.
@tobychow4761
@tobychow4761 8 ай бұрын
love this sol
@naaz2659
@naaz2659 3 ай бұрын
Why are we setting Prev = cur * prev and not prev = cur? It will be very helpful if u answer this cause am stuck here
@Andrew-dd2vf
@Andrew-dd2vf 26 күн бұрын
because multiplication / division takes precedence over addition / subtraction. E.g. 2 * 4 + 3, after you encounter the number "4", your prev will be updated to 2* 4 = 8. And so when a new operator (in this case, +) is encountered, you can simply add 3 with (2*4) instead of, say, 4 individually, which would clearly be wrong
@kalp2586
@kalp2586 3 ай бұрын
Explanation at 4:47 is wrong. You want to undo the 3 + 5 operation, so it would be 8 - 5 , not 8 - 3. Best to avoid this approach. Stack based approach is much simpler.
@crackfaang
@crackfaang 3 ай бұрын
Stack is easier but you will not pass with this question if you use extra space. You need to do it in O(1) space in a real interview unfortunately. Stack is considered too easy
@subee128
@subee128 8 ай бұрын
Thanks
@aditijain2448
@aditijain2448 Жыл бұрын
good code
@crackfaang
@crackfaang Жыл бұрын
Thanks!
BASIC CALCULATOR III | LEETCODE # 772 | PYTHON SOLUTION
13:05
Cracking FAANG
Рет қаралды 7 М.
Как подписать? 😂 #shorts
00:10
Денис Кукояка
Рет қаралды 8 МЛН
Don't look down on anyone#devil  #lilith  #funny  #shorts
00:12
Devil Lilith
Рет қаралды 20 МЛН
إخفاء الطعام سرًا تحت الطاولة للتناول لاحقًا 😏🍽️
00:28
حرف إبداعية للمنزل في 5 دقائق
Рет қаралды 52 МЛН
Basic Calculator II | Leet code 227 | Theory explained + Python code
19:27
BASIC CALCULATOR | LEETCODE # 224 | PYTHON SOLUTION
21:06
Cracking FAANG
Рет қаралды 22 М.
ACCOUNTS MERGE | LEETCODE # 721 | PYTHON SOLUTION
23:04
Cracking FAANG
Рет қаралды 10 М.
Valid Palindrome II - Leetcode 680 - Python
7:46
NeetCode
Рет қаралды 46 М.
EXCLUSIVE TIME OF FUNCTIONS | LEETCODE 636 | PYTHON SOLUTION
15:42
Cracking FAANG
Рет қаралды 4,6 М.
What is 0 to the power of 0?
14:22
Eddie Woo
Рет қаралды 10 МЛН
227. Basic Calculator II , Top Interview DSA Questions, Java Solution with time complexity
16:12
SDE Concepts in 10Mins - by Shrayansh
Рет қаралды 2,4 М.
LOWEST COMMON ANCESTOR OF A BINARY TREE III [PYTHON]
16:38
Cracking FAANG
Рет қаралды 10 М.
Как подписать? 😂 #shorts
00:10
Денис Кукояка
Рет қаралды 8 МЛН