# NINJA’S ARRAY

Posted: 21 Mar, 2021
Difficulty: Moderate

## PROBLEM STATEMENT

#### Example:

``````Case 1:
Suppose given array of distinct integers ‘ARR' = [10, 35] and array of integers array ‘PIECES' = [ ,  ]. So, we return ‘True’ as we can form such array-like first we concatenate , then  hence it is possible to make ‘ARR’ from ‘PIECES’.

Case 2:
Suppose if the array of distinct integers ‘ARR' = [ 2, 1, 3 ] and an array of integers array ‘PIECES' = [ [ 1, 2 ], [ 3 ] ]. So we return ‘False’ as we cant form such an array because we can’t change the order of [ 1, 2 ].
``````

#### Input Format:

``````The first line of input contains a ‘T’ number of test cases.

The first line of each test case contains an integer ‘N’, which represents the size of the array ‘ARR’.

The second line of each test case contains the ‘N’ space-separated integer of array ‘ARR’.

The third line of each test case contains an integer ‘M’ denoting the number of rows in array ‘PIECES’. Then, ‘M’ lines follow.

Each line contains an integer ‘R' denoting the number of columns in that row and ‘R’ space-separated integers denoting the values of the row.
``````

#### Output Format:

``````For each test case, print in a line ‘True’ if it is possible to form else print  ‘False’.

Print the output of each test case in a separate line.
``````
##### Note:
``````You do not need to print anything, it has already been taken care of. Just implement the given function.
``````

#### Constraints:

``````1 <= T <= 10
1 <= M <= N <= 1000
1 <= R <= 1000
1 <= ARR[i], PIECES[i][j] <=100

Time Limit: 1 second
`````` Approach 1

Algorithm:

1. We have to check each and every element of ‘ARR’ in ‘PIECES’ for this we start traversing our ‘ARR’ and for each element ‘ARR[i]’ we check if there exists an array present in ‘PIECES’ such that it starts from ‘ARR[i]’ or not.
2. If it founds to be true we increment our ‘i’ and search for the next elements in the same way.
3. Else we return ‘False’ if the above condition failed.
4. Now we traverse until ‘i’ becomes equal to ‘N’ size of ‘ARR’ if we are able to traverse the whole array by holding the above condition we return ‘True'.