Challenge - 5 Problems
Jump Game Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of Jump Game Reachability Check
What is the output of this Go code that checks if you can jump to the last index?
DSA Go
package main import "fmt" func canJump(nums []int) bool { maxReach := 0 for i := 0; i < len(nums); i++ { if i > maxReach { return false } if i+nums[i] > maxReach { maxReach = i + nums[i] } } return true } func main() { nums := []int{2,3,1,1,4} fmt.Println(canJump(nums)) }
Attempts:
2 left
💡 Hint
Think about whether the jumps allow reaching the last index.
✗ Incorrect
The code tracks the furthest reachable index. Since the input allows reaching the end, it returns true.
❓ Predict Output
intermediateOutput for Unreachable Last Index
What does this Go code print when the last index is not reachable?
DSA Go
package main import "fmt" func canJump(nums []int) bool { maxReach := 0 for i := 0; i < len(nums); i++ { if i > maxReach { return false } if i+nums[i] > maxReach { maxReach = i + nums[i] } } return true } func main() { nums := []int{3,2,1,0,4} fmt.Println(canJump(nums)) }
Attempts:
2 left
💡 Hint
Check if the zero at index 3 blocks progress.
✗ Incorrect
The zero at index 3 prevents reaching index 4, so the function returns false.
🔧 Debug
advancedIdentify the Bug in Jump Game Code
What error does this Go code produce when run?
DSA Go
package main import "fmt" func canJump(nums []int) bool { maxReach := 0 for i := 0; i < len(nums); i++ { if i > maxReach { return false } if i+nums[i] > maxReach { maxReach = i + nums[i] } } return true } func main() { nums := []int{2,3,1,1,4} fmt.Println(canJump(nums)) }
Attempts:
2 left
💡 Hint
Check the loop condition and array indexing carefully.
✗ Incorrect
The loop goes to i <= len(nums), which causes an index out of range panic when accessing nums[i].
🧠 Conceptual
advancedMinimum Jumps to Reach Last Index
Given an array where each element represents max jump length, which approach finds the minimum number of jumps to reach the last index?
Attempts:
2 left
💡 Hint
Think about tracking the farthest reachable index within current jumps.
✗ Incorrect
The greedy approach efficiently tracks the current jump boundary and updates the next max reach to count minimum jumps.
🚀 Application
expertOutput of Minimum Jumps Calculation
What is the output of this Go code that calculates minimum jumps to reach the last index?
DSA Go
package main import "fmt" func jump(nums []int) int { jumps, curEnd, curFarthest := 0, 0, 0 for i := 0; i < len(nums)-1; i++ { if i+nums[i] > curFarthest { curFarthest = i + nums[i] } if i == curEnd { jumps++ curEnd = curFarthest } } return jumps } func main() { nums := []int{2,3,1,1,4} fmt.Println(jump(nums)) }
Attempts:
2 left
💡 Hint
Count how many times you need to jump to cover the array.
✗ Incorrect
The minimum jumps to reach the last index is 2 for this input.
