Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a vector for the result levels.
DSA Rust
let mut results: Vec<Vec<i32>> = [1];Attempts:
3 left
💡 Hint
Common Mistakes
Using Vec::with_capacity without initializing elements.
Using Vec::default which may not be clear for beginners.
✗ Incorrect
We use vec![] to create an empty vector to store levels.
2fill in blank
mediumComplete the code to pop the first node from the queue.
DSA Rust
let node = queue.[1]().unwrap();Attempts:
3 left
💡 Hint
Common Mistakes
Using pop() which is for Vec, not VecDeque.
Using pop_back() which removes from the end.
✗ Incorrect
pop_front() removes and returns the first element from the VecDeque queue.
3fill in blank
hardFix the error in the code to reverse the current level vector when needed.
DSA Rust
if left_to_right == false { current_level.[1](); }
Attempts:
3 left
💡 Hint
Common Mistakes
Using sort() which sorts elements instead of reversing.
Using rotate_left() which rotates elements but does not reverse.
✗ Incorrect
reverse() reverses the elements in place, needed for zigzag order.
4fill in blank
hardFill both blanks to add children nodes to the queue if they exist.
DSA Rust
if let Some(left) = node.[1] { queue.[2](left); }
Attempts:
3 left
💡 Hint
Common Mistakes
Using push_front which adds to the front, breaking BFS order.
Accessing right child instead of left in this code block.
✗ Incorrect
We check node.left and push_back to add to the queue's end.
5fill in blank
hardFill all three blanks to toggle direction and push right child to queue.
DSA Rust
left_to_right = ![1]; if let Some(right) = node.[2] { queue.[3](right); }
Attempts:
3 left
💡 Hint
Common Mistakes
Using push_front which breaks BFS order.
Not toggling the direction variable correctly.
✗ Incorrect
Toggle left_to_right boolean, access right child, and push_back to queue.
