i'm confident i can solve both problems in under 10 minutes with my eyes closed. these days the problem isn't passing the technical. it's getting one in the first place. job hunt is rough 😞
In the 2nd question can we this For every node starting from root find the height of left subtree and right subtree . Now, if height of left subtree is more this means deepest node is in left one and we move to that tree and vice versa. And move recursively untill height of both tree becomes equal then just return that node. I think that might work and it's easy to 😀😀
@@Sharky-c3z hmm were not looking for the deepest node but for a node that contains all of the deepest nodes under it. There can be multiple nodes that contain the deepest nodes and we need to capture the lowest one in the tree. If we just had to return any we would just return the root everytime. Let me know if that makes sense.
@@jamesperaltaSWE it is pre- requisite that leaf nodes are always the deepest node and height of a tree is nothing but a traversal from a specific node to its deepest descendant leaf node so this solution might work. 😀
the first problem, literally one line: set(nums).intersect(set(nums2)) is that rly what faang interview is like? swe for 5 yrs. I did the second one fairly quick too..
I don't work for a faang or faang adjacent company but if a candidate returned your solution I'd push them to solve it without using utility functions. I assume faang interviews won't make you write a bubble sort from scratch but won't accept certain utility functions in answers
@@fadsa342 I’ve done FAANG interviews before and have lots of friends in FAANG right now and most will ask you 2 questions in a 45 - 60min interview. The first is usually an easy warm up that they’ll expect you to breeze through before asking you a harder question. Since this is just the warmup question I think this would suffice as long as you can explain what’s happening under the hood.
I wish it was standard practice for leetcode style problems to discourage the usage of utility methods in languages' standard libraries. Using high-level functions, like the intersection method, to solve low-level problems seems antithetical to the essence of leetcode/DS&A problems. Interviewers want to see how you work through problems and think. For trivial problems like the intersection of two arrays, it would probably be more beneficial if you wrote the intersection method from scratch. For more complex problems, using helper methods is fine. It really only seems silly in the context of easy problems. However in normal day SWE doing this would probably make a lot of other devs mad at you, so maybe youd have to explicitly tell the interviewer why you decided to implement X method from scratch instead of using the built-in function.
Ahh yup that makes sense. It would definitely be something you should discuss with the interviewer before implementing. I first talk about how I would do it manually and then decided to just use built-in functions but probably my interviewer would stop me there and tell me which one he preferred. But honestly if I didn’t want a candidate to use built-in functions I would create a variation of the problem where built-in functions wouldn’t be as useful.
Hey i have a doubt... What if( in cpp) 1) First see which array is larger.. Using If loop and storing it N 2) take a unordered set (avg tc 0(1) for insertion) and copy down all the elements of that larger arrray of size N 3) iterate through the smaller array and do mst.find(arr[i]) 4) if i dont find the element then i am gonna erase that element in the unordered set. 5) copy down the elements to a list or array and return it... my TC-----> 0(larger array size) My SC-----> 0(2N) Your TC---> 0(nums1.size() +nums2.size()) Your SC---> 0(3N)
The two nodes of the last level which are farthest from each other (leftmost and right most) will cover all the intermediary parents of other nodes which are at last level. So subtree root will be the lca of these two left most and right most node.
But yeah some people are saying it’s easy lmao they must be studying a lot. If you haven’t done leetcode in a while the second would be nearly impossible unless your really good at DSA
@@michaelrodrigues6372 practice makes perfect!! Just keep on grinding LeetCode questions and you’ll eventually get there 🙏 I was bad at one point also and after a few months of consistent effort I improved substantially.
Shoutout to leetcode.com/ for providing the platform! You will need to pay for premium to access this feature but it is well worth it!
Holy shit, Meta just hire the man already
LOL
not until after another 20 rounds with exponentially increasing difficulty at each round 😂😂
@shkhamd fr 😂😂 it be like that
i'm confident i can solve both problems in under 10 minutes with my eyes closed.
these days the problem isn't passing the technical. it's getting one in the first place. job hunt is rough 😞
It’s rough forsure :// where are you based and how’s your resume? Maybe I can give some advice on that.
Hey, would you like to review my resume and give me some tips?🙂 any advice would help me
@Nikola79797 I’m down! Can you send it to me in the discord? discord.gg/9hS5tqnVSs
@ sure! Thanks
@jamesperaltaSWE I think I replied earlier today with a link, pretty sure yt removed it. I'll send it through discord as well, many thanks!
In the 2nd question can we this
For every node starting from root find the height of left subtree and right subtree .
Now, if height of left subtree is more this means deepest node is in left one and we move to that tree and vice versa.
And move recursively untill height of both tree becomes equal then just return that node.
I think that might work and it's easy to 😀😀
A reply would be appreciated 😅
@@Sharky-c3z hmm were not looking for the deepest node but for a node that contains all of the deepest nodes under it. There can be multiple nodes that contain the deepest nodes and we need to capture the lowest one in the tree. If we just had to return any we would just return the root everytime. Let me know if that makes sense.
@@jamesperaltaSWE it is pre- requisite that leaf nodes are always the deepest node and height of a tree is nothing but a traversal from a specific node to its deepest descendant leaf node so this solution might work. 😀
@@jamesperaltaSWE Moreover just submitted my code and it worked ;)
Have a look ,Sorry it's in c++🥲
class Solution {
public:
TreeNode* ans = NULL;
int height(TreeNode* root)
{
if(!root) return 0;
int lh = 1 + height(root->left);
int rh = 1 + height(root->right);
return max(lh , rh);
}
TreeNode* helper(TreeNode* root)
{
if(!root) return NULL;
if(!root->left && !root->right) return root;
int lh = height(root->left);
int rh = height(root->right);
if(lh == rh) return root;
if(lh > rh) return helper(root->left) ;
return helper(root->right);
}
TreeNode* subtreeWithAllDeepest(TreeNode* root) {
return helper(root);
}
};
@@jamesperaltaSWE Just coded it out and it worked ;)
Have a look
class Solution {
public:
int height(TreeNode* root)
{
if(!root) return 0;
int lh = 1 + height(root->left);
int rh = 1 + height(root->right);
return max(lh , rh);
}
TreeNode* helper(TreeNode* root)
{
if(!root) return NULL;
if(!root->left && !root->right) return root;
int lh = height(root->left);
int rh = height(root->right);
if(lh == rh) return root;
if(lh > rh) return helper(root->left) ;
return helper(root->right);
}
TreeNode* subtreeWithAllDeepest(TreeNode* root) {
return helper(root);
}
};
I've worked with this guy and he's insanely good!
@@philipsoerensen you as well!! And congrats on raising $2 million for your AI Startup 🚀
the first problem, literally one line: set(nums).intersect(set(nums2))
is that rly what faang interview is like? swe for 5 yrs. I did the second one fairly quick too..
First question is a bit easy your right but I think a lot of candidates would get stumped on Q2
I don't work for a faang or faang adjacent company but if a candidate returned your solution I'd push them to solve it without using utility functions. I assume faang interviews won't make you write a bubble sort from scratch but won't accept certain utility functions in answers
@@fadsa342 I’ve done FAANG interviews before and have lots of friends in FAANG right now and most will ask you 2 questions in a 45 - 60min interview. The first is usually an easy warm up that they’ll expect you to breeze through before asking you a harder question. Since this is just the warmup question I think this would suffice as long as you can explain what’s happening under the hood.
@@fadsa342 but also I don’t think they’ll ask something this easy haha
I wish it was standard practice for leetcode style problems to discourage the usage of utility methods in languages' standard libraries.
Using high-level functions, like the intersection method, to solve low-level problems seems antithetical to the essence of leetcode/DS&A problems.
Interviewers want to see how you work through problems and think. For trivial problems like the intersection of two arrays, it would probably be more beneficial if you wrote the intersection method from scratch. For more complex problems, using helper methods is fine. It really only seems silly in the context of easy problems.
However in normal day SWE doing this would probably make a lot of other devs mad at you, so maybe youd have to explicitly tell the interviewer why you decided to implement X method from scratch instead of using the built-in function.
Ahh yup that makes sense. It would definitely be something you should discuss with the interviewer before implementing. I first talk about how I would do it manually and then decided to just use built-in functions but probably my interviewer would stop me there and tell me which one he preferred.
But honestly if I didn’t want a candidate to use built-in functions I would create a variation of the problem where built-in functions wouldn’t be as useful.
Hey i have a doubt...
What if( in cpp)
1) First see which array is larger.. Using If loop and storing it N
2) take a unordered set (avg tc 0(1) for insertion) and copy down all the elements of that larger arrray of size N
3) iterate through the smaller array and do
mst.find(arr[i])
4) if i dont find the element then i am gonna erase that element in the unordered set.
5) copy down the elements to a list or array and return it...
my TC-----> 0(larger array size)
My SC-----> 0(2N)
Your TC---> 0(nums1.size() +nums2.size())
Your SC---> 0(3N)
@@VamshiV-g9r think that works but sounds overly complicated
now my algorithm and data structure course actually makes sense.
Love that haha. Goodluck with your studies!
W video as always
Will you please make a video for dsa in python as there are not much resources out there on this
@@Ved-vi2gb I have this playlist! ua-cam.com/play/PL1_cEA1Q0Z8-WO_mXqu8Nf0ObhxhqnBI-.html&feature=shared
Will add more to it in the next couple of weeks
another banger 🔥
Thanks bro!
For second question just find the lowest common ancestor of first and last node of last level.
@@amanshrivastava7495 ahh yeah your right that would probably work too! It wouldn’t work with any other two nodes but yup you’re right 🔥
The two nodes of the last level which are farthest from each other (leftmost and right most) will cover all the intermediary parents of other nodes which are at last level. So subtree root will be the lca of these two left most and right most node.
@@amanshrivastava7495 yup I agree it will work if you take the last and first node
for the first question can we just use the inbuilt methods in an interview? is that accepted? in python.
Yup I think in built is fine here. I wouldn’t mind if I was the one hosting the interview.
could use the & operator to find intersection as well lol
@ ohh interesting I was only familiar with ‘.intersection’
During my interview at Meta they asked me not to for the sake of the interview. I would just ask though.
@storyofbo ahhh okay I see! Makes sense thanks for the insight 😁
lmao the Comments are lying talking about this is so easy
actual engineers struggle to do this without studying Leetcode and DSA first
Hahah yeah I agree these are hard 😭😭
But yeah some people are saying it’s easy lmao they must be studying a lot. If you haven’t done leetcode in a while the second would be nearly impossible unless your really good at DSA
Yoo James any tips to get better at coding bro? my problem solving skills are bad dude :(
@@michaelrodrigues6372 practice makes perfect!! Just keep on grinding LeetCode questions and you’ll eventually get there 🙏 I was bad at one point also and after a few months of consistent effort I improved substantially.
@@michaelrodrigues6372 try following these steps for something more prescriptive: ua-cam.com/video/i4dw_HAbNBI/v-deo.htmlfeature=shared
Also upload more videos on teaching dsa
@@Ved-vi2gb will do!
@@Ved-vi2gb which videos are you looking for specifically?
Savage 🔥🔥
Thanks for watching brother!! 🔥
i cannot eat if I understand this point, just sent to AI to solve this problem.
@@dian_permana LOL yeah AI can probably solve this easy
@@jamesperaltaSWE so what do you think bro? I am from Indonesia struggle with this point. Wasting time but in the same time everyone using AI 😀
Are you asking if AI will replace Software Engineering?
@@jamesperaltaSWE no, I want to know the trend in your country, how about fresher use this and impacted to career path in the future
@@dian_permana Sorry I don’t understand the question completely. So you’re asking how a freshman can use AI?
🔥🔥🔥
@Grogu1999 💪💪
nice
@@qy-exotic7717 thanks!!
😂 hmm lol maybe let’s do a mock interview on me in a couple of months and see how many negative indicators I have
@johnperaltaCFA LOL bettt
@johnperaltaCFA we can do the Bloomberg one
😂 lol give me a prep plan and I’ll study it on the side
Bem legal, gostei, vou tentar.
Good, liked, I'll try
Let’s go! 💪💪 keep me updated
class Solution {
public:
int depth(TreeNode*& root){
return !root?0:max(depth(root->left),depth(root->right))+1;
}
TreeNode* subtreeWithAllDeepest(TreeNode* root) {
if(!root) return nullptr;
int left=depth(root->left);
int right=depth(root->right);
if(left==right) return root;
if(left>right) return subtreeWithAllDeepest(root->left);
else return subtreeWithAllDeepest(root->right);
}
};
Let me try this I think it'll work
There are definitely more succinct ways to solve this compared to what I did haha
savage
@@Caesar6310 🚀
u was cheating
how? I'm using a single monitor lol you can see everything I do there.
@ ur head go left and see another monitor
@@nim_a123 just thinking haha trust me I don’t need to cheat