- Denisse's Newsletter
- Posts
- There's No Way All Your Hard Work Won't Lead to Something Amazing 🔥
There's No Way All Your Hard Work Won't Lead to Something Amazing 🔥
Day 3 of master level by level trees


TLDR
Welcome!
The recommendations I live by!
Self-Gaslight of the week
JOBS & SCHOLARSHIPS
Hello and welcome back brave human being!
99% of life is mastering your emotions.
What you eat, think, spend, and do is mastered by your emotions.
And once you master your emotions, you master your life.
Easier said than done, but once you master staring at a problem, thinking it through, stepping back, and coming back to solve it, you'll begin to crack everything wide open.
LFG!!
LeetCode problem
Given the root of a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.
Before we dive in,
Breathe
Nothing is ever that deep.
Now, let’s
But there is a little trick that I am about to teach you….
We’re going to leverage recursion to navigate through the tree and a map to store the nodes level by level, where the key is the level and the value is an array with the nodes in that level.
We are simply going to iterate through the tree INORDER, and store in our map the current node we are processing and their level:
treeNodes[level].push_back(root->val);
And every time we call our recursive function, we’re simply going to add 1 to our level so that when we traverse deeper into the tree, we know exactly where we are:
auxLevelOrder(root->left, level + 1);
auxLevelOrder(root->right, level + 1);
This approach allows us to group nodes together INORDER by their levels as we go down the tree.
Once we have a map with the levels and nodes, we know exactly how to extract the right-side view. For each level, the last node in the array is the one visible from the right side.
Finally, we gather all these last nodes from each level and return them as the result. This method ensures we capture the rightmost nodes at every level, giving us the desired right-side view of the binary tree.

Complete code:
void auxRightSideView(TreeNode* root, int level){ //InOrder
if(root==NULL){
return;
}
auxRightSideView(root->left, level+1);
nodes_by_level[level].push_back(root->val);
auxRightSideView(root->right, level+1);
}
vector<int> rightSideView(TreeNode* root) {
auxRightSideView(root,0);
vector<int>right_side_nodes;
for (const auto& [key, value] : nodes_by_level) {
right_side_nodes.push_back(value.back());
}
return right_side_nodes;
}
Want SOC 2 compliance without the Security Theater?
Question 🤔 does your SOC 2 program feel like Security Theater? Just checking pointless boxes, not actually building security?
In an industry filled with security theater vendors, Oneleet is the only security-first compliance platform that provides an “all in one” solution for SOC 2.
We’ll build you a real-world Security Program, perform the Penetration Test, integrate with a 3rd Party Auditor, and provide the Compliance Software … all within one platform.
Hacks of the week
Want to get a job at a start up? Browse through Tech Week’s event, message the host and everyone who works at the VC thanking them for hosting the event (which you never went to)
Always act as if you know the person 👀 keep them guessing
Self-gaslight of the week
I truly believe you can gaslight yourself to success.
Jobs and Scholarships
Cheers to you hacking your week,
Denisse
Reply