JAVA | ~O(n) 0ms runtime | with Explanation
Idea:\nStore the pieces in such a way that each array piece is linked and first element of each piece should be accessible in O(1) time. Hence using a HashMap. 
Idea:\nStore the pieces in such a way that each array piece is linked and first element of each piece should be accessible in O(1) time. Hence using a HashMap. Then, traverse the arr and check if each value exits as a key (rest of the values in the arraylist of each key will be indexed over & checked in for loop)\neg: \n```\narr = [91,4,64,8,78,2], pieces = [[78,2],[4,64,8],[91]]\nHashMap:\n78-> [78,2]\n4-> [4,64,8]\n91-> [91]\n\n[91,4,64,8,78,2] (91 exists as a key and [91] an array of values)\n ^ \n[91,4,64,8,78,2] (4 exists as a key and [4,64,8] an array of values)\n    ^  * *\n[91,4,64,8,78,2] (78 exists as a key and [78,2] an array of values )\n\t\t    ^ * \n```\t\t   \n```\nclass Solution {\n    public boolean canFormArray(int[] arr, int[][] pieces) {\n        HashMap<Integer,int[]> hm = new HashMap();\n        for(int[] list:pieces)\n            hm.put(list[0],list);\n        \n        int index = 0;\n        while(index<arr.length){\n            if(!hm.containsKey(arr[index]))\n                return false;\n            \n            int[] list = hm.get(arr[index]);\n            for(int val:list){\n                if(index>=arr.length || val!=arr[index])\n                    return false;\n                index++;\n            }\n        }\n        return true;\n    }\n}\n```\n
['Java']