LC 1640 [E] Check Array Formation Through Concatenation - ALawliet/algorithms GitHub Wiki

hashmap where we use the item in the first list as a key since we can't rearrange the list

class Solution:
    def canFormArray(self, arr: List[int], pieces: List[List[int]]) -> bool:
        mp = {x[0]: x for x in pieces}
        res = []
        
        for num in arr:
            res += mp.get(num, [])
            
        return res == arr