[JS] Using Hashmap - O(n) time and space
\nvar canFormArray = function(arr, pieces) {\n\t// create map of pieces with key as first element of a piece to the piece\n    const map = new Map();  // O(n)\n
```\nvar canFormArray = function(arr, pieces) {\n\t// create map of pieces with key as first element of a piece to the piece\n    const map = new Map();  // O(n)\n    pieces.forEach(piece => map.set(piece[0], piece));    // O(n)\n\t\n\t// traverse through the array, check if there is any piece starting with it (ordering within piece should be same)\n\t// if piece exist, traverse through the array and piece parallely and\n\t// check if the elements match.\n\t// when piece is traversed completely, look for another piece and follow the same \n    for(let idx = 0; idx < arr.length;) {    // O(n)\n\t\t// exit case 1: no piece with current element\n        if(!map.has(arr[idx])) {    // O(1)\n            return false;\n        }\n        const piece = map.get(arr[idx]);    // O(1)\n        let pIdx = 0;\n        while(pIdx < piece.length) {    // max - O(n)\n\t\t\t// exit case 2: while traversing, the piece and array index values mismatch\n            if(piece[pIdx] !== arr[idx]) {\n                return false;\n            }\n            ++pIdx;\n            ++idx;\n        }\n    }\n\t// exit case 3: checked for all the elements in the array and matches it with pieces, so return true\n    return true;\n};\n```\nTime Complexity = O(n)\nSpace Complexity = O(n)
['JavaScript']