Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize the left pointer at the start of the array.
DSA Rust
let mut left = [1];Attempts:
3 left
💡 Hint
Common Mistakes
Starting the pointer at 1 instead of 0.
Using the length of the array as the starting index.
✗ Incorrect
The left pointer should start at index 0, which is the first element of the array.
2fill in blank
mediumComplete the code to initialize the right pointer at the end of the array.
DSA Rust
let mut right = arr.[1]() - 1;
Attempts:
3 left
💡 Hint
Common Mistakes
Using start() method which does not exist.
Using capacity() which may be larger than length.
✗ Incorrect
The right pointer should start at the last index, which is length of the array minus one.
3fill in blank
hardFix the error in the while loop condition to continue while left is less than right.
DSA Rust
while left [1] right {
Attempts:
3 left
💡 Hint
Common Mistakes
Using >= or <= which causes incorrect loop termination.
Using > which skips the case when pointers are equal.
✗ Incorrect
The loop should run while left pointer is less than right pointer to avoid overlap.
4fill in blank
hardFill both blanks to move the left pointer right and the right pointer left inside the loop.
DSA Rust
left [1] 1; right [2] 1;
Attempts:
3 left
💡 Hint
Common Mistakes
Using -= for left pointer which moves it backward.
Using += for right pointer which moves it forward.
✗ Incorrect
The left pointer moves forward by adding 1, the right pointer moves backward by subtracting 1.
5fill in blank
hardFill all three blanks to create a two-pointer loop that prints pairs of elements from both ends.
DSA Rust
while [1] < [2] { println!("{} - {}", arr[[1]], arr[[2]]); [1] += 1; [2] -= 1; }
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up left and right pointers in the print statement.
Not updating pointers inside the loop.
✗ Incorrect
The loop uses left and right pointers to print pairs and moves them towards each other.
