[Java] Easy to Understand O(n) Solution
This is a easy problem but it is a liitle bit tricky. To solve this problem, we will need to:\n1. Compare the number from pieces to arr to make your life easier
This is a easy problem but it is a liitle bit tricky. To solve this problem, we will need to:\n1. Compare the number **from pieces to arr** to make your life easier.\n2. **If we cannot find the number in arr, return false immediately.**\n3. If we find this number in arr, we also need to **do further checking if the current piece\'s length longer than one**. So we will check whether *map.get(p[i]) == ++index;*.\n4. If all cases are valid, finally we will return the answer as true.\n```\n    public boolean canFormArray(int[] arr, int[][] pieces) {\n        if (arr.length == 0)\n            return true;\n        Map<Integer, Integer> map = new HashMap<>(); // value to index in arr.\n        for (int i = 0; i < arr.length; i++) {\n            map.put(arr[i], i);\n        }\n        for (int[] p : pieces) {\n            if (!map.containsKey(p[0])) return false;\n            int index = map.get(p[0]);\n            for (int i = 1; i < p.length; i++) { // if current piece\'s length > 1, we do further check.\n                if (!map.containsKey(p[i]) || map.get(p[i]) != ++index) return false;\n            }\n        }\n        return true;\n    }\n```
[]