0
0
DSA Cprogramming~30 mins

Jump Game Problem in DSA C - Build from Scratch

Choose your learning style9 modes available
Jump Game Problem
📖 Scenario: Imagine you are playing a video game where you need to jump across platforms. Each platform lets you jump forward up to a certain number of steps. You want to check if you can reach the last platform starting from the first one.
🎯 Goal: You will write a program to determine if it is possible to jump from the first platform to the last platform using the jump lengths given for each platform.
📋 What You'll Learn
Create an array called jumps with the exact values: {2, 3, 1, 1, 4}
Create an integer variable called n that stores the length of the jumps array
Write a function called canJump that takes the jumps array and n as parameters and returns 1 if you can reach the last platform, otherwise 0
Print the result of calling canJump(jumps, n)
💡 Why This Matters
🌍 Real World
This problem models situations where you need to check if a sequence of steps or moves can reach a goal, such as in games, pathfinding, or network packet routing.
💼 Career
Understanding this problem helps in software engineering roles that involve algorithm design, problem solving, and optimization.
Progress0 / 4 steps
1
Create the jumps array
Create an integer array called jumps with the exact values {2, 3, 1, 1, 4}.
DSA C
Hint

Use int jumps[] = {2, 3, 1, 1, 4}; to create the array.

2
Create the length variable
Create an integer variable called n that stores the length of the jumps array using sizeof(jumps) / sizeof(jumps[0]).
DSA C
Hint

Use int n = sizeof(jumps) / sizeof(jumps[0]); to get the array length.

3
Write the canJump function
Write a function called canJump that takes an integer array jumps and its length n as parameters. The function should return 1 if you can reach the last platform starting from the first, otherwise return 0. Use a variable maxReach to track the farthest platform reachable so far and iterate through the array to update it.
DSA C
Hint

Use a loop to check if the current index is reachable and update the maximum reachable index.

4
Print the result
Print the result of calling canJump(jumps, n) using printf.
DSA C
Hint

Use printf("%d\n", canJump(jumps, n)); inside main to print the result.