Challenge - 5 Problems
Right Side View Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of Right Side View for a Simple Binary Tree
What is the output of the right side view function for the given binary tree?
DSA C
struct TreeNode {
int val;
struct TreeNode *left;
struct TreeNode *right;
};
// Tree structure:
// 1
// / \
// 2 3
// \ \
// 5 4
// Right side view output expected: [1, 3, 4]Attempts:
2 left
💡 Hint
The right side view shows the rightmost node at each level.
✗ Incorrect
At level 1, node 1 is visible. At level 2, node 3 is visible (right child). At level 3, node 4 is visible (right child of 3).
🧠 Conceptual
intermediateUnderstanding Right Side View Node Selection
In the right side view of a binary tree, which nodes are included in the output?
Attempts:
2 left
💡 Hint
Think about what you see when looking at the tree from the right side.
✗ Incorrect
The right side view includes the rightmost node visible at each level of the tree.
❓ Predict Output
advancedOutput of Right Side View for Unbalanced Tree
What is the output of the right side view function for this unbalanced binary tree?
DSA C
// Tree structure: // 10 // / // 5 // \ // 7 // \ // 9 // Expected output: [10, 5, 7, 9]
Attempts:
2 left
💡 Hint
Right side view includes the rightmost node at each depth level.
✗ Incorrect
At level 1: 10; level 2: 5 (only node); level 3: 7 (right child of 5); level 4: 9 (right child of 7).
🔧 Debug
advancedIdentify the Error in Right Side View Implementation
What error will this code produce when trying to get the right side view of a binary tree?
DSA C
void rightSideViewHelper(struct TreeNode* root, int level, int* maxLevel, int* result, int* returnSize) { if (!root) return; if (level > *maxLevel) { result[(*returnSize)++] = root->val; *maxLevel = level; } rightSideViewHelper(root->right, level + 1, maxLevel, result, returnSize); rightSideViewHelper(root->left, level + 1, maxLevel, result, returnSize); } // The helper visits right child before left child.
Attempts:
2 left
💡 Hint
Check the order of traversal in the helper function.
✗ Incorrect
Visiting right child before left child causes the first node at each level to be the rightmost, so right side nodes are captured correctly.
🚀 Application
expertNumber of Nodes in Right Side View for Complete Binary Tree
Given a complete binary tree with height h (root at height 1), how many nodes will the right side view contain?
Attempts:
2 left
💡 Hint
Right side view shows one node per level.
✗ Incorrect
In a complete binary tree, the right side view shows exactly one node per level, so the count equals the height h.
