[Python3] 2-line O(N)
Algo\nWe can leverage on the fact that the integers in pieces are distinct and define a mapping mp to map from the first element of piece to piece. Then, we cou
Algo\nWe can leverage on the fact that the integers in `pieces` are distinct and define a mapping `mp` to map from the first element of piece to piece. Then, we could linearly scan `arr` and check if what\'s in arr `arr[i:i+len(mp[x])]` is the same as the one in piece `mp[x]`. \n\nImplementation\n```\nclass Solution:\n    def canFormArray(self, arr: List[int], pieces: List[List[int]]) -> bool:\n        mp = {x[0]: x for x in pieces}\n        i = 0\n        while i < len(arr): \n            if (x := arr[i]) not in mp or mp[x] != arr[i:i+len(mp[x])]: return False \n            i += len(mp[x])\n        return True \n```\n\nEdited on 11/01/2020 \nAdding a 2-line implementation \n```\nclass Solution:\n    def canFormArray(self, arr: List[int], pieces: List[List[int]]) -> bool:\n        mp = {x[0]: x for x in pieces}\n        return sum((mp.get(x, []) for x in arr), []) == arr\n```\n\nAnalysis\nTime complexity `O(N)`\nSpace complexity `O(N)`
['Python3']