Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare the function that prints the left side view of a binary tree.
DSA C++
void [1](TreeNode* root) { if (!root) return; // Implementation here }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a function name that suggests right side view.
Using a generic name that does not indicate left view.
✗ Incorrect
The function is commonly named 'leftView' to indicate it prints the left side view of the tree.
2fill in blank
mediumComplete the code to declare a queue for level order traversal.
DSA C++
std::queue<TreeNode*> [1]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'stack' which is a different data structure.
Using 'list' which is not a queue.
✗ Incorrect
The variable 'q' is commonly used as a short name for a queue in traversal algorithms.
3fill in blank
hardFix the error in the condition to check if the current node has a left child.
DSA C++
if (current->[1]) { q.push(current->left); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Checking 'right' instead of 'left'.
Using invalid member names like 'child' or 'node'.
✗ Incorrect
To check if the current node has a left child, use 'left' pointer.
4fill in blank
hardFill both blanks to correctly update the level size and iterate through nodes at that level.
DSA C++
int [1] = q.size(); for (int i = 0; i < [2]; i++) { TreeNode* current = q.front(); q.pop(); // process current }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variables causing mismatch in loop iterations.
Using variable names that are not descriptive.
✗ Incorrect
Using the same variable 'levelSize' to store the size and iterate ensures correct traversal of one level.
5fill in blank
hardFill all three blanks to correctly add the first node's value of each level to the result vector.
DSA C++
if (i == [1]) { result.[2](current->[3]); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong index instead of 0.
Using incorrect vector method like 'add' or 'append'.
Accessing node value with wrong member name.
✗ Incorrect
The first node at each level has index 0; we add its value to result using push_back and access value with 'val'.