Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to start iterating over the jump array.
DSA Go
for [1] := 0; [1] < len(nums); [1]++ {
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable not declared in the loop header.
✗ Incorrect
The loop variable should be 'i' to iterate over the array indices.
2fill in blank
mediumComplete the code to update the furthest reachable index.
DSA Go
if i + nums[i] > [1] { maxReach = i + nums[i] }
Attempts:
3 left
💡 Hint
Common Mistakes
Using an undefined variable name.
✗ Incorrect
We compare with 'maxReach' to update the furthest reachable index.
3fill in blank
hardFix the error in the condition to check if the current index is reachable.
DSA Go
if i > [1] { return false }
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing 'i' with itself or array length incorrectly.
✗ Incorrect
If current index 'i' is beyond 'maxReach', it means we cannot reach it.
4fill in blank
hardFill both blanks to complete the function signature and return type.
DSA Go
func canJump(nums []int) [1] { maxReach := 0 for i := 0; i < len(nums); i++ { if i > maxReach { return [2] } if i + nums[i] > maxReach { maxReach = i + nums[i] } } return true }
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong return type or returning true too early.
✗ Incorrect
The function returns a boolean, and returns false if the current index is unreachable.
5fill in blank
hardFill all three blanks to complete the main function that tests canJump.
DSA Go
func main() {
nums := []int[1]
result := canJump(nums)
if result == [2] {
fmt.Println("Can reach the end")
} else {
fmt.Println("Cannot reach the end")
}
}Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong slice syntax or wrong boolean values.
✗ Incorrect
The array {2,3,1,1,4} allows reaching the end, so result is true; {3,2,1,0,4} is an example input.
