Binary Tree Right Side View || Leetcode 199 || 2 Variant Questions Big Tech Actually Asks

preview_player
Показать описание
Discover the actual variants Meta asks on Leetcode problem 199: Binary Tree Right Side View.

Timestamps:
00:00 Leetcode Explanation
06:02 Leetcode Coding
07:38 Variant #1 Explanation: Left & Right Side Views
12:15 Variant #1 Coding: Left & Right Side Views
13:21 Variant #2 Explanation: Print Both Views
14:48 Variant #2 Coding: Print Both Views

Follow us on social media:

GitHub:

More Context:
FAANG, mid-sized companies, and startups are asking more LeetCode-style puzzle questions every day, making it harder to stand out as the competition grows. With an increasing number of new graduates entering the software market and tech companies laying off developers while overworking those who remain, it’s a tough landscape. Take Meta, for example: they expect 2-3 months of intense study time, only to likely ghost you afterward. But this doesn’t mean we should be unprepared.

While LeetCode is a valuable learning resource, many developers focus too much on rote memorization. Others find themselves stuck in a vicious cycle, where they don’t study as efficiently as they could because they’re juggling multiple responsibilities. They have full-time jobs, personal commitments, or other obligations that limit the time they can dedicate to solving problems. It’s a grind. Unfortunately, most companies introduce their own twists or "variants" of common problems (e.g., 6-sum instead of 2-sum), which throw candidates off. Rephrasings of problems and follow-up questions are also common, so recognizing these variations and curveballs is crucial.

For those who don’t have the time to revisit LeetCode problems multiple times to solidify concepts, this channel covers the most frequently asked variants, rephrasings, and follow-ups. If you've seen these before, you’ll have a significant edge over your competitors. Remember, time pressure — especially at Meta — is intense, so speed is essential. Even with thorough preparation, interviewers may be unpredictable, but knowing the variants beforehand can drastically increase your chances of success.

Take LeetCode 199, Binary Tree Right Side View, which is one of Meta’s most frequently asked questions (top 20 as of writing). Meta rarely sticks with the original problem. Variants - however - do exist, and with thousands of interviewers, it's hard to predict them all. We cover 2 key variants: one, what if you had to return a vector of not only the right side view but also the left side view? Two, what if you had to print both side views instead of returning the vector?

We also walk through variants in mock interviews. Using the exact platform (CoderPad) that Meta uses, you’ll get familiar with the UI, settings, and overall experience. This is a 1-on-1 simulation of how Meta conducts and facilitates their interviews, so the goal is to avoid wasting time on the tool itself. Once again, time limits at Meta are a huge factor, so speed is critical.

That said, even with perfect preparation, interviewers might not always be in a good mood or may judge unfairly. The interview process has its power dynamics, but with insider knowledge, you’ll have done as much as you can on your end to secure a Strong Hire decision.
Рекомендации по теме
Комментарии
Автор

During an interview, it might be worth mentioning that the queue uses at most O(n/2) nodes, and the left and right side are of size O(height).

Also, instead of putting conditional logic inside of the loop, you should be putting it outside by using .back() and .front().

n_x
Автор

Like you mentioned, for the second variant, if we dont do left and right arrays, we can do one queue and appendleft for the left and append for the right, super easy.

TheBarinco
Автор

Hi Minmer, can you give some context a bit? How do you know that these variants are what Meta actually asks? Can you disclose? They are great practice regardless (and infinite thank you again for even taking the the time to do this), but was just curious.

tangled
Автор

question:
how about normal tree traversal (dfs style)?
right view = rRL
left view = rLR

tc : 2 * o(n)
sc: height of tree, since not balanced, o(n).

foobar
Автор

Can we just use postorder and preorder for L and R side views?

I feel it is cleaner, but might need a traversal for each variant, ex: preorder uses the fact that we visit the rightmost node at the end and we can just store the ans for each depth and overwrite.

vector<int> rightSideView(TreeNode* root)
{
std::vector<int> ans;
findView(root, 0, ans);
return ans;
}

void findView(TreeNode* root, int depth, std::vector<int>& ans)
{
if(!root)
return;
if(depth == ans.size())
{
ans.push_back(0);
}

ans[depth] = root->val;
findView(root->left, depth + 1, ans);
findView(root->right, depth + 1, ans);
}

padmanabh
Автор

I heard Meta also ask the "The bottom view of the tree". I would assume that would need a DFS approach where we save the column of each node and use that to store the nodes in the right order ?

codeMasteryHq
Автор

Could we move the lines 17 and 19 above the for loop. Size gives us the number of nodes in the level. (we can get both front and back from the queue to get the left and right ).

codewiz
Автор

for the variant, what about the case:
1
2
3 4
Wouldn't this duplicate the "2" entry?

subhanc
Автор

In the case you draw, 8 shows up twice. Shouldn't we only include one 8 either in left or right?

serein
Автор

Could you please create meta variant for adjacent duplicates removal in string

harshalpatil
Автор

Another variant is that ask to solve it using dfs

ilanaizelman
visit shbcf.ru