Java Using HashMap O(N)
Explanation: We can use HashMap to record indexes, and as long as the indexes are in the same order as how it is presented in the piece, it works.\n@pgmreddy th
Explanation: We can use HashMap to record indexes, and as long as the indexes are in the same order as how it is presented in the piece, it works.\n@pgmreddy thank you for the test case - I have updated the code and added comment for the line I have edited!\n```\nclass Solution {\n    public boolean canFormArray(int[] arr, int[][] pieces) {\n        if(pieces == null || pieces.length == 0) return false;\n        HashMap<Integer, Integer> map = new HashMap<>();\n        for(int i = 0; i < arr.length; i++) {\n            map.put(arr[i], i);\n        }\n        int prev;\n        for(int[] piece : pieces){\n            prev = -1;\n            for(int num : piece){\n                if(!map.containsKey(num)) return false;\n                if(prev != -1){\n                    if(map.get(num) != prev + 1) return false;  // the next number in the piece must also be the next number in the target array\n                }\n                prev = map.get(num);\n            }\n        }\n        return true;\n    }\n}\n```\n\nFeel free to leave comments or advice and Upvote for others to see!\nThanks!!
['Java']