BASIC CALCULATOR III | LEETCODE # 772 | PYTHON SOLUTION

  Рет қаралды 7,494

Cracking FAANG

Cracking FAANG

Күн бұрын

Пікірлер: 14
@landocodes
@landocodes 9 ай бұрын
My Meta phone screen is tomorrow and I think I found a video for every Meta question I ran into (except for maybe 1 that I can't remember).. Just wanted to say thanks again for the hard work man. I'll be recommending this channel to everyone I see prepping for Meta and hopefully I'll pass to the onsite and get more utility out of it.
@crackfaang
@crackfaang 9 ай бұрын
Thanks for the kind words and best of luck with the phone screen. I'm sure you'll smash it!
@landocodes
@landocodes 9 ай бұрын
Thanks man I passed!@@crackfaang Now it's time to check out your System Design playlist :)
@aman4434
@aman4434 9 ай бұрын
how was it? Mine was supposed to be tomorrow and its now gotten rescheduled lol. I'm watching this channel too! But still nervous...
@landocodes
@landocodes 9 ай бұрын
@@aman4434it went well! I heard that I passed the next day. If you’ve done the top meta questions, and get a good interviewer, then it should be a breeze! Just make sure to communicate your ideas and have a good understanding of the solution you’ve chosen.
@landocodes
@landocodes 9 ай бұрын
It went well! I was a bit nervous for a second but my interviewer was amazing. She calmed me down and told me to just let my thoughts out. Once I did that I got back on track and everything went smoothly! Heard back the next morning that I passed! As long as you have the majority of the medium/easy top 100 meta questions complete then I'm sure you'll do fine! Good luck :)@@aman4434
@ziyiyang4550
@ziyiyang4550 2 жыл бұрын
Great solution! It's the most clean one I've seen. Implementing DFS using stack is definitely a pain lol
@davidoh6342
@davidoh6342 Жыл бұрын
in line 34, if op=s[i], will it become ")" ???
@def__init
@def__init Жыл бұрын
yes but it's fine because if the string still has more after ")", the following MUST be a new OP, like 2*(...)/3 from the examples. And when we process the "/" after, which will first call helper with op being ")", which will do nothing. Then business as usual, num back to 0 and op set to "/"
@amadoufall6237
@amadoufall6237 2 жыл бұрын
Good job on your videos. Could you please do this one next? 1267. Count Servers that Communicate. I would really appreciate to hear your explanations
@crackfaang
@crackfaang 2 жыл бұрын
Thanks for the kind words and your support. I’ll add that question to my work queue and make sure you subscribe so you don’t miss the upload
@kn7419533
@kn7419533 2 ай бұрын
Another solution to reuse Cracking FAANG's code for 227. Basic Calculator II without using stack, we can do class Solution { public: int calculate(string s) { int i = 0; return calculateHelper(s, i); } int calculateHelper(string& s, int& i) { int cur = 0, prev = 0, res = 0; char cur_operation = '+'; while (i < s.length()) { char cur_char = s[i]; if (isdigit(cur_char)) { cur = 0; // Extract the full number while (i < s.length() && isdigit(s[i])) { cur = cur * 10 + (s[i] - '0'); // Convert character to integer i++; } i--; // Adjust index to process the next character properly // Perform operation based on the previous operator if (cur_operation == '+') { res += cur; prev = cur; } else if (cur_operation == '-') { res -= cur; prev = -cur; } else if (cur_operation == '*') { res -= prev; prev = prev * cur; res += prev; } else if (cur_operation == '/') { res -= prev; prev = prev / cur; res += prev; } } else if (cur_char == '(') { i++; // Move past '(' cur = calculateHelper(s, i); // Recursively evaluate parentheses*** // Perform the operation (same as the previous block) if (cur_operation == '+') { res += cur; prev = cur; } else if (cur_operation == '-') { res -= cur; prev = -cur; } else if (cur_operation == '*') { res -= prev; prev = prev * cur; res += prev; } else if (cur_operation == '/') { res -= prev; prev = prev / cur; res += prev; } } else if (cur_char == ')') { // Return result if we encounter a closing parenthesis return res; } else if (cur_char != ' ') { // Store the operator for the next calculation cur_operation = cur_char; } // else --> ' ' (skip it) i++; } return res; }
@garimagupta4208
@garimagupta4208 Жыл бұрын
great explanation
BASIC CALCULATOR II | LEETCODE 227 | PYTHON SOLUTION
15:40
Cracking FAANG
Рет қаралды 25 М.
Farmer narrowly escapes tiger attack
00:20
CTV News
Рет қаралды 12 МЛН
FOREVER BUNNY
00:14
Natan por Aí
Рет қаралды 32 МЛН
Noodles Eating Challenge, So Magical! So Much Fun#Funnyfamily #Partygames #Funny
00:33
Python 101: Learn the 5 Must-Know Concepts
20:00
Tech With Tim
Рет қаралды 1,2 МЛН
My 10 “Clean” Code Principles (Start These Now)
15:12
Conner Ardman
Рет қаралды 287 М.
LeetCode Basic Calculator 1-3 中文解释 Chinese Version
19:08
Basic Calculator II | Leet code 227 | Theory explained + Python code
19:27
Basic Calculator | Leetcode 224 | Live coding session 🔥🔥🔥
17:01
why are switch statements so HECKIN fast?
11:03
Low Level
Рет қаралды 428 М.
Walking Robot Simulation - Leetcode 874 - Python
14:02
NeetCodeIO
Рет қаралды 10 М.
227. Basic Calculator II , Top Interview DSA Questions, Java Solution with time complexity
16:12
SDE Concepts in 10Mins - by Shrayansh
Рет қаралды 2,9 М.
772. Basic Calculator III , Top Interview DSA Questions, Java Solution with time complexity
15:49
SDE Concepts in 10Mins - by Shrayansh
Рет қаралды 1,3 М.
Dynamic Programming isn't too hard. You just don't know what it is.
22:31
DecodingIntuition
Рет қаралды 199 М.