DEV Community

dev.to staff
dev.to staff

Posted on

3 1

Daily Challenge #164 - Jump

Setup

Jump is a simple one-player game:

You are initially at the first cell of an array of cells containing non-negative integers;
At each step you can jump ahead in the array as far as the integer at the current cell, or any smaller number of cells. You win if there is a path that allows you to jump from one cell to another, eventually jumping past the end of the array, otherwise you lose.

Examples

For instance, if the array contains the integers
[2, 0, 3, 5, 0, 0, 3, 0, 0, 3, 1, 0],
you can win by jumping from 2, to 3, to 5, to 3, to 3, then past the end of the array.
You can also directly jump from from the initial cell(first cell) past the end of the array if they are integers to the right of that cell.

E.g
[6, 1, 1] is winnable
[6] is not winnable
Note: You can not jump from the last cell!
[1, 1, 3] is not winnable

Tests

canJump([5])
canJump([2, 5])
canJump([3, 0, 2, 3])
canJump([4, 1, 2, 0, 1])
canJump([5, 0, 0, 0])
canJump([1, 1])

Thanks for reading! Have fun.


This challenge comes from kodejuice on CodeWars. Thank you to CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!

Want to propose a challenge idea for a future post? Email yo+challenge@dev.to with your suggestions!

Sentry image

Make it make sense

Only get the information you need to fix your code that’s broken with Sentry.

Start debugging →

Top comments (1)

Collapse
 
idanarye profile image
Idan Arye

Not sure I understand the rules - why is [6] not winnable? Because you can't jump from the last cell, or because the last jump must be exact? The note says "You can not jump from the last cell!" but it can be interpreted as either "the last cell can never be jumped from" or "the last cell in this case is 6, so you can't do a one cell jump over the edge".

Is [3, 0] winnable? The last jump needs to be of 2, which is allowed from a 3 unless the rule is last-jump-needs-to-be-exact.

Is [1] winnable? You need to do a 1-jump from the 1, which is OK unless the rule is can't-jump-from-last-cell.

Feature flag article image

Create a feature flag in your IDE in 5 minutes with LaunchDarkly’s MCP server ⏰

How to create, evaluate, and modify flags from within your IDE or AI client using natural language with LaunchDarkly's new MCP server. Follow along with this tutorial for step by step instructions.

Read full post

👋 Kindness is contagious

Discover fresh viewpoints in this insightful post, supported by our vibrant DEV Community. Every developer’s experience matters—add your thoughts and help us grow together.

A simple “thank you” can uplift the author and spark new discussions—leave yours below!

On DEV, knowledge-sharing connects us and drives innovation. Found this useful? A quick note of appreciation makes a real impact.

Okay