[Java] O(n)
Explanation:\n1. first, all elements are distinct (if not, this problem becomes more harder)\n2. for each array in the pieces array, all of those elements shoul
Explanation:\n1. first, all elements are distinct (if not, this problem becomes more harder)\n2. for each array in the pieces array, all of those elements should be adjecent in the A array(since all of them are unique), then we can rearrange them\n3. We should also do addtional check if the numbers of elemens in pieces is equal to A and if all of them are identical\n\n```\nclass Solution {\n    public boolean canFormArray(int[] A, int[][] pieces) {\n        int n=0;\n        Map<Integer,Integer>map=new HashMap<>();\n        for(int i=0;i<A.length;i++){\n            map.put(A[i],i);\n        }\n        \n        for(int pair[]:pieces){\n            n+=pair.length;\n            if(!map.containsKey(pair[0]))return false;\n            for(int i=1;i<pair.length;i++){\n                if(!map.containsKey(pair[i]))return false;\n                int index1=map.get(pair[i]);\n                int index2=map.get(pair[i-1]);\n                if(index1-index2!=1)return false;\n            }\n        }\n        if(n!=map.size())return false;\n        return true;\n    }\n}\n```
[]