Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Desolve/d7ca363defdd266301bc5f37e956e7d4 to your computer and use it in GitHub Desktop.
Save Desolve/d7ca363defdd266301bc5f37e956e7d4 to your computer and use it in GitHub Desktop.
1640 Check Array Formation Through Concatenation
class Solution:
def canFormArray(self, arr: List[int], pieces: List[List[int]]) -> bool:
idx = {}
for i in range(len(pieces)):
idx[pieces[i][0]] = i
cnt = 0
while cnt < len(arr):
if arr[cnt] not in idx:
return False
p = idx[arr[cnt]]
for n in pieces[p]:
if n != arr[cnt]:
return False
cnt += 1
return True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment