Leetcode 1760 Solution
This article provides solution to leetcode question 1760 (check-array-formation-through-concatenation)
Access this page by simply typing in "lcs 1760" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/check-array-formation-through-concatenation
Solution
class Solution:
def canFormArray(self, arr: List[int], pieces: List[List[int]]) -> bool:
pieces_dict = {p[0]: p for p in pieces}
i = 0
while i < len(arr):
p = pieces_dict.get(arr[i])
if not p:
return False
for j in range(len(p)):
if i >= len(arr) or arr[i] != p[j]:
return False
i += 1
return True