mapping
to store the first integer of each piece as the key and the entire piece as the value.i
to 0 to track the current position in arr
.i
is less than the length of arr
, do the following:
a. Check if arr[i]
is in the hashmap mapping
.
b. If not, return false
as no piece starts with arr[i]
.
c. Retrieve the piece from mapping
using arr[i]
as the key.
d. Check if the piece matches the subarray of arr
starting at index i
.
e. If it matches, increment i
by the length of the piece.
f. If it does not match, return false
.arr
is reached, return true
.