FunctionRacerProblemsRace

Is It a Prefix

BeginnerLinked listsPython, JavaScript, TypeScript, Java, C++

Return True if the values of list a appear at the very start of list b, in order. An empty a is a prefix of every list, and a list is a prefix of itself.

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

a [1,2]
b [1,2,3]
returns true

b starts with 1, 2.

Example 2

a [2,3]
b [1,2,3]
returns false

b starts with 1, not 2.

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