Opening your workspace…
Workspace/Coding room
Opening your workspace…
On the Island, the castaways have marked a trail from the beach to the hatch in equal spaces. The last strip of daylight reaches just far enough to see the sinkholes on their map. They want to cross in as few moves as possible.
The beach is space 0 and the hatch is at the nonnegative integer length. You also receive blocked, a set of sinkhole positions strictly between them. Each move takes you forward one or two spaces. You may step over a sinkhole, but you must land on dry ground. Return the fewest moves that land you exactly at the hatch, or −1 if you cannot reach it. If length is 0, you are already there and the answer is 0.
4, []Output2Two double steps reach space 4.
4, [1,2]Output-1Neither first landing is dry.
For a dry space, compare arriving from one and two spaces back.
function solve(length, blocked) { // 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.