C beats 88%, O(n) solution Explained
Solution\nc\nbool canFormArray(int* arr, int arrSize, int** pieces, int piecesSize, int* piecesColSize){\n\n    int pmap[101];    \n    for(int i=0; i<piecesSiz
### Solution\n```c\nbool canFormArray(int* arr, int arrSize, int** pieces, int piecesSize, int* piecesColSize){\n\n    int pmap[101];    \n    for(int i=0; i<piecesSize; ++i){\n        int j=0;\n        while(j<piecesColSize[i]){\n            if(j-1<0){\n                // First (and possibly only) value, has no previous neighbour\n                pmap[pieces[i][j]] = -1;\n            }else{ \n                pmap[pieces[i][j]] = pieces[i][j-1];\n            }\n            ++j;\n        }\n    }\n    \n    // Check if value exists and is piece-togetherable \n    for(int i=0; i<arrSize; ++i){\n        if(pmap[arr[i]]==0){\n            return false;\n        }\n        // has a neighbour. peek one value back and check equality\n        if(pmap[arr[i]]>0){\n            if(i==0 || arr[i-1]!=pmap[arr[i]]) return false;\n        }\n    }\n    return true; \n}\n```\n### Explanation\nThis algorithm uses a mapping technique and passes through the arrays twice.\n\nThe first `for` loop tracks occurences for every value in `pieces`, where the index of the mapping array, `pmap`, relates to the value of the element in `pieces`.\n\nIf the element is part of a `piece` with more than one element, we set the value of the element in `pmap` to be the previous element in `piece`. This is used later on to verify that the multi-element `pieces[i]` can actually be used to form `arr` without rearranging the elems in `pieces[i]`.\n\nThe second loop basically checks that:\n1. The element exists (note: unless assigned, the \'default\' initialisation for an int array is `0`.)\n2. As mentioned earlier, `pieces[i]` need not be rearranged.\n
['C']