Opening your workspace…
Workspace/Coding room
Opening your workspace…
Your friend's Nether portal has gone dark, and they are stuck on the far side with a very dramatic piglin audience. You find glowstone on a chain of basalt stepping stones across a lava lake. The stones have mile-markers painted on them; the first is at 0, and the portal is at the last marker. You can leap forward at most reach markers at a time, but you can land only on a listed stone. What is the fewest leaps needed to reach the portal with the glowstone? If no route works, report -1.
[0,2,5,6,10], 4Output3Leap 0→2, 2→6, then 6→10. Two leaps cannot cover the route using these stones.
[0,3,6,9], 3Output3Each gap is exactly the maximum reach, so you need all three leaps.
On each leap take the farthest stone within reach.
function solve(stones, reach) { // Write your solution here. }
Tab inserts two spaces. Shift+Tab outdents. Use the arrow keys and Tab to choose a suggestion. Press Escape, then Tab, to leave the editor. Press Control or Command with apostrophe to run samples or with Enter to submit.