Java HashMap O(N)
Use a hashmap to keep track of (head of a piece, the whole piece).\n2. Traverse every element in arr and compare every element with those in pieces.\n\n\n    pu
1. Use a hashmap to keep track of ```(head of a piece, the whole piece)```.\n2. Traverse every element in ```arr``` and compare every element with those in ```pieces```.\n\n```\n    public boolean canFormArray(int[] arr, int[][] pieces) {\n        HashMap<Integer, int[]> map = new HashMap<>();\n        for(int i = 0; i < pieces.length; i++) {\n            map.put(pieces[i][0], pieces[i]);\n        }\n        for(int i = 0; i < arr.length;) {\n            if(!map.containsKey(arr[i])) return false;\n            int[] p = map.get(arr[i]);\n            for(int j = 0; j < p.length; j++, i++) {\n                if(arr[i] != p[j]) return false;\n            }\n        }\n        return true;\n    }\n```\n\nTime: ```O(N)```, ```N``` is the length of ```arr```\nSpace: ```O(M)```, ```M``` is the length of ```pieces```
[]