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.
@@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.
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
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 "/"
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; }
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.
Thanks for the kind words and best of luck with the phone screen. I'm sure you'll smash it!
Thanks man I passed!@@crackfaang Now it's time to check out your System Design playlist :)
how was it? Mine was supposed to be tomorrow and its now gotten rescheduled lol. I'm watching this channel too! But still nervous...
@@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.
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
Great solution! It's the most clean one I've seen. Implementing DFS using stack is definitely a pain lol
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
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
in line 34, if op=s[i], will it become ")" ???
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 "/"
great explanation
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;
}