FunctionRacerProblemsRace

Hop to the End

EasyLinked listsPython, JavaScript, TypeScript, Java, C++

You stand on the head. Each hop moves you forward by exactly the number written on the node you are standing on. Keep hopping until you land on the last node or jump past the end. Return True only if you land exactly on the last node. The list is passed in as head.

Linked lists appear in the tests as the list of their values, like [1,2,3]. Each node is a ListNode with .val and .next; the class is already defined for you.

Example 1

head [2,9,1,9,9]
returns false

Index 0, then 2, then 3, then a hop of 9 jumps past the end without landing on index 4.

Example 2

head [2,9,1,3]
returns true

Index 0 -> 2 -> 3, which is the last node.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Linked lists problems