Challenge - 5 Problems
Array Deletion Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput after deleting first element from a Rust vector
What is the output of this Rust code after deleting the first element from the vector?
DSA Rust
fn main() {
let mut v = vec![10, 20, 30, 40];
v.remove(0);
println!("{:?}", v);
}Attempts:
2 left
💡 Hint
Removing element at index 0 shifts all elements left.
✗ Incorrect
The remove(0) call deletes the first element (10). The vector then contains [20, 30, 40].
❓ Predict Output
intermediateResult of shifting elements after deletion
What will be printed after deleting the first element from this Rust vector?
DSA Rust
fn main() {
let mut v = vec![5, 15, 25, 35, 45];
v.remove(0);
println!("{:?}", v);
}Attempts:
2 left
💡 Hint
Removing index 0 shifts all elements left by one.
✗ Incorrect
The first element 5 is removed, so the vector becomes [15, 25, 35, 45].
🔧 Debug
advancedWhy does this Rust code panic when deleting the first element?
This Rust code panics when trying to remove the first element. What is the cause?
DSA Rust
fn main() {
let mut v: Vec<i32> = Vec::new();
v.remove(0);
}Attempts:
2 left
💡 Hint
Check if the vector has any elements before removing.
✗ Incorrect
Calling remove(0) on an empty vector causes a panic because index 0 does not exist.
❓ Predict Output
advancedOutput after multiple deletions at beginning
What is the output after removing the first element twice from this Rust vector?
DSA Rust
fn main() {
let mut v = vec![1, 2, 3, 4, 5];
v.remove(0);
v.remove(0);
println!("{:?}", v);
}Attempts:
2 left
💡 Hint
Each remove(0) deletes the current first element and shifts left.
✗ Incorrect
First remove deletes 1, vector becomes [2,3,4,5]. Second remove deletes 2, vector becomes [3,4,5].
🧠 Conceptual
expertTime complexity of deleting the first element in a Rust vector
What is the time complexity of deleting the first element from a Rust vector using remove(0)?
Attempts:
2 left
💡 Hint
Consider what happens to elements after the removed index.
✗ Incorrect
Removing the first element requires shifting all subsequent elements left by one, which takes linear time O(n).
