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 the following C# code that checks if you can jump to the last index of the array?
DSA C#
using System; class Program { static bool CanJump(int[] nums) { int maxReach = 0; for (int i = 0; i < nums.Length; i++) { if (i > maxReach) return false; maxReach = Math.Max(maxReach, i + nums[i]); } return true; } static void Main() { int[] nums = {2, 3, 1, 1, 4}; Console.WriteLine(CanJump(nums)); } }
Attempts:
2 left
💡 Hint
Think about whether the jumps allow reaching the last index.
✗ Incorrect
The code tracks the farthest index reachable. Since the array allows jumps to reach the end, it returns True.
❓ Predict Output
intermediateOutput for Unreachable Last Index
What will the output be for this C# code when the last index is not reachable?
DSA C#
using System; class Program { static bool CanJump(int[] nums) { int maxReach = 0; for (int i = 0; i < nums.Length; i++) { if (i > maxReach) return false; maxReach = Math.Max(maxReach, i + nums[i]); } return true; } static void Main() { int[] nums = {3, 2, 1, 0, 4}; Console.WriteLine(CanJump(nums)); } }
Attempts:
2 left
💡 Hint
Check if the zero blocks progress to the last index.
✗ Incorrect
The zero at index 3 blocks any further jump, so the last index cannot be reached.
🔧 Debug
advancedIdentify the bug in Jump Game code
What error will this C# code produce when trying to check jump reachability?
DSA C#
using System; class Program { static bool CanJump(int[] nums) { int maxReach = 0; for (int i = 0; i <= nums.Length; i++) { if (i > maxReach) return false; maxReach = Math.Max(maxReach, i + nums[i]); } return true; } static void Main() { int[] nums = {2, 3, 1, 1, 4}; Console.WriteLine(CanJump(nums)); } }
Attempts:
2 left
💡 Hint
Check the loop condition and array indexing carefully.
✗ Incorrect
The loop runs until i <= nums.Length which causes an index out of range when accessing nums[i] at the last iteration.
🧠 Conceptual
advancedMinimum Jumps to Reach Last Index
Given an array where each element represents the max jump length at that position, which approach correctly finds the minimum number of jumps to reach the last index?
Attempts:
2 left
💡 Hint
Think about how to track jumps efficiently without exploring all paths.
✗ Incorrect
The greedy approach efficiently tracks the farthest reachable index within the current jump and increments jumps when moving beyond it.
❓ Predict Output
expertOutput of Minimum Jumps Calculation
What is the output of this C# code that calculates the minimum number of jumps to reach the last index?
DSA C#
using System; class Program { static int MinJumps(int[] nums) { if (nums.Length <= 1) return 0; int jumps = 0, currentEnd = 0, farthest = 0; for (int i = 0; i < nums.Length - 1; i++) { farthest = Math.Max(farthest, i + nums[i]); if (i == currentEnd) { jumps++; currentEnd = farthest; } } return jumps; } static void Main() { int[] nums = {2, 3, 1, 1, 4}; Console.WriteLine(MinJumps(nums)); } }
Attempts:
2 left
💡 Hint
Count how many jumps are needed to cover the array.
✗ Incorrect
The minimum jumps to reach the last index in this array is 2: jump from index 0 to 1, then from 1 to 4.
