Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if the current position can jump to the last index.
DSA Rust
if i + nums[i] >= [1] { return true; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 instead of the last index.
Using nums[0] which is the first element, not the last index.
Using i which is the current index, not the last.
✗ Incorrect
We compare the current index plus its jump length to the last index, which is nums.len() - 1.
2fill in blank
mediumComplete the code to update the farthest reachable index.
DSA Rust
let farthest = farthest.max(i + [1]);
Attempts:
3 left
💡 Hint
Common Mistakes
Using i instead of nums[i] for jump length.
Using farthest instead of nums[i].
Using nums.len() which is unrelated here.
✗ Incorrect
We update farthest with the maximum of current farthest and i plus nums[i], the jump length at i.
3fill in blank
hardFix the error in the loop condition to iterate over all indices.
DSA Rust
for i in 0..[1] {
Attempts:
3 left
💡 Hint
Common Mistakes
Using nums.len() - 1 which excludes the last index.
Using nums.len() + 1 which is invalid.
Using nums.len() / 2 which skips many indices.
✗ Incorrect
We loop from 0 to nums.len() because Rust ranges exclude the upper bound, so this iterates over all indices.
4fill in blank
hardFill both blanks to check if the current index is reachable and update farthest.
DSA Rust
if i <= [1] { farthest = farthest.max(i + [2]); }
Attempts:
3 left
💡 Hint
Common Mistakes
Checking i <= nums.len() which is unrelated.
Using i instead of farthest in the condition.
Using nums.len() instead of nums[i] for jump length.
✗ Incorrect
We check if i is reachable by comparing it to farthest, then update farthest using nums[i] jump length.
5fill in blank
hardFill all three blanks to return if the last index is reachable after the loop.
DSA Rust
return farthest [1] [2] - 1; // where [3] is the length of nums
Attempts:
3 left
💡 Hint
Common Mistakes
Using < instead of >=
Comparing to nums.len() instead of nums.len() - 1.
Using == which is too strict.
✗ Incorrect
We return true if farthest is greater than or equal to the last index (nums.len() - 1).
