Basic Calculator II | Leet code 227 | Theory explained + Python code

  Рет қаралды 11,733

Sai Anish Malla

Sai Anish Malla

Күн бұрын

Пікірлер: 30
@symbol767
@symbol767 2 жыл бұрын
This is the best explanation on the problem I've seen. After your explanation I was able to code it out on my own. Thank you so much.
@jamesperalta35
@jamesperalta35 3 жыл бұрын
For 18:30, the reason it wasn't coming out correct was because the question says "The integer division should truncate toward zero." When you perform integer division, you get the floor which would result in rounding -0.333 to -1 when it should round to 0 based on the description. int() however rounds towards 0 which is why it works.
@saianishmalla2646
@saianishmalla2646 3 жыл бұрын
Thanks for explaining!
@thechunwu
@thechunwu 2 жыл бұрын
In a situation like: "14-3/2" I find the int() rounds to -2 rather than -1 because in this case its rounding down. which is a greater negative number?
@tzujuiyu
@tzujuiyu 3 ай бұрын
@@thechunwu -1 is greater than -2. In your example, this expression int(-3/2) should evaluate to -1. I wonder if you added an extra ''/' by chance. int(-3//2) gives you -2
@am_0x2a
@am_0x2a 9 ай бұрын
Great video! A further optimization would be to eliminate the stack altogether and keep a running sum. Instead of appending to the stack, just add. Instead of popping, just keep track of the most recent value and subtract it off. Then you can save yourself the extra loop to go through and sum all the values. Specifically, it will bring storage complexity from O(n) to O(1) and reduce time by a factor of 2 (though it will still be O(n)).
@BreakthroughCreator
@BreakthroughCreator 2 жыл бұрын
this is one of the best coding teaching videos so far, nice voice, cadence, explanation, and visuals
@anoops7974
@anoops7974 2 ай бұрын
Thank you Sai Anish. Great video and explanation.
@grovestreet9165
@grovestreet9165 2 жыл бұрын
if you're indian then your accent is realy too good
@HarshitaKhazanchi
@HarshitaKhazanchi 10 ай бұрын
this really cleared things up!
@n.h.son1902
@n.h.son1902 6 ай бұрын
Great visualization! It helps build my intuition a lot for this challenge. There're a couple of ways to handle the edge case about the operator == "/", one way we can think of is to take advantage of the built-in function math.floor() and math.ceil(). Cheers!
@LARamones23
@LARamones23 4 жыл бұрын
Thanks for the nice explanation! Your videos are very helpful. Integer division for negative number is the issue for stack[-1] //= curr_num. For example -3//4 returns -1 in python but 3//4 returns 0. Following approach seems also to be working. if stack[-1] >=0 : stack[-1] //= curr_num else: stack[-1] = -(-stack[-1]//curr_num)
@saianishmalla2646
@saianishmalla2646 4 жыл бұрын
Glad the videos help! Thanks for explaining why int division didn't work it makes sense.
@vidyutphagetra3804
@vidyutphagetra3804 3 жыл бұрын
good explanation Anish
@kevinzheng575
@kevinzheng575 3 жыл бұрын
Nice information. Thank you!
@sugamff8825
@sugamff8825 4 жыл бұрын
Big fan bro ❤️
@saianishmalla2646
@saianishmalla2646 4 жыл бұрын
ayyeee thank you!!!
@ishayadav001
@ishayadav001 4 жыл бұрын
Love your videos!!
@saianishmalla2646
@saianishmalla2646 4 жыл бұрын
Glad you like them!
@linli7049
@linli7049 3 жыл бұрын
Very good explanation!
@sakshiramsinghani5284
@sakshiramsinghani5284 3 жыл бұрын
Thanks a lot! It's really helpful.
@user-kg9lm4mp8j
@user-kg9lm4mp8j 2 жыл бұрын
//是整除,int()是取整,题目要求向0取整,整除遇到负数会出错。
@shrimpo6416
@shrimpo6416 2 жыл бұрын
Bc int div round towards zero. So it gets weird when rounding neg num
@aminesfahani3563
@aminesfahani3563 3 жыл бұрын
thanks i want to share this code class Solution: def myPow(self, x: float, n: int) -> float: if n==0: return 1 elif n
@Chancemm
@Chancemm 4 жыл бұрын
Thank you!!
@saianishmalla2646
@saianishmalla2646 4 жыл бұрын
You're welcome !!
@diegogarcia-pl1bt
@diegogarcia-pl1bt 2 жыл бұрын
you just stole the answer from the discussion you clearly do not understand the code
@PremPal-uy4nm
@PremPal-uy4nm Жыл бұрын
It seems he didn't explain clearly how char & operator are working together to add values in stack to make correct calculation as we move through the string. In short char is leading in for loop and operator is lagging.
@n.h.son1902
@n.h.son1902 6 ай бұрын
@@PremPal-uy4nm if I remember it right, he did. His explanation in the visualization meant that the variable “operator” in the code is the previous operator in the illustration and the variable “char” means the current operator we are at.
Next Permutation | Leet code 31 | Theory explained + Python code
19:19
Sai Anish Malla
Рет қаралды 15 М.
Basic Calculator | Leetcode 224 | Live coding session 🔥🔥🔥
17:01
Accompanying my daughter to practice dance is so annoying #funny #cute#comedy
00:17
Funny daughter's daily life
Рет қаралды 11 МЛН
А я думаю что за звук такой знакомый? 😂😂😂
00:15
Денис Кукояка
Рет қаралды 3,6 МЛН
ТЮРЕМЩИК В БОКСЕ! #shorts
00:58
HARD_MMA
Рет қаралды 2,6 МЛН
Hoodie gets wicked makeover! 😲
00:47
Justin Flom
Рет қаралды 134 МЛН
BASIC CALCULATOR II | LEETCODE 227 | PYTHON SOLUTION
15:40
Cracking FAANG
Рет қаралды 24 М.
Code with Jess - Leetcode #224 Basic Calculator
7:43
Jessica Lin
Рет қаралды 19 М.
227. Basic Calculator II , Top Interview DSA Questions, Java Solution with time complexity
16:12
SDE Concepts in 10Mins - by Shrayansh
Рет қаралды 2,9 М.
How to STUDY so FAST it feels like CHEATING
8:03
The Angry Explainer
Рет қаралды 1,8 МЛН
BASIC CALCULATOR III | LEETCODE # 772 | PYTHON SOLUTION
13:05
Cracking FAANG
Рет қаралды 7 М.
How I Failed the Google Coding Interview (and lessons I learned)
14:24
Jump Game II - Leetcode 45 - Recursive Backtracking (Python)
9:37
BASIC CALCULATOR | LEETCODE # 224 | PYTHON SOLUTION
21:06
Cracking FAANG
Рет қаралды 25 М.
Leetcode - Basic Calculator (Python)
7:29
Timothy H Chang
Рет қаралды 13 М.
Accompanying my daughter to practice dance is so annoying #funny #cute#comedy
00:17
Funny daughter's daily life
Рет қаралды 11 МЛН