Python the most optimal solution: O(n) time, O(n) space with hashmap
\nclass Solution:\n    def canFormArray(self, arr: List[int], pieces: List[List[int]]) -> bool:\n        res = []\n       \n        n = len(arr)\n        indexe
```\nclass Solution:\n    def canFormArray(self, arr: List[int], pieces: List[List[int]]) -> bool:\n        res = []\n       \n        n = len(arr)\n        indexes = {}\n        for i in range(len(pieces)):\n            indexes[pieces[i][0]] = i \n        idx = 0 \n        while idx < n:\n            if arr[idx] not in indexes:\n                return False\n            item = pieces[indexes[arr[idx]]]\n            for j in range(len(item)):\n                if arr[idx+j] != item[j]:\n                    return False\n                else:\n                    res.append(item[j])\n            idx += len(item)\n        return True\n            \n```
['Python', 'Python3']