Check if concatenation of any permutation of given list of arrays generates the given array

Solution for geeksforgeeks problem

def solve(arr, sub_arrs):

    sub_arr_membership = {}
    curr_indx = [-1 for i in range(0, len(sub_arrs))]
    for idx, sub_arr in enumerate(sub_arrs):
        for sub_arr_idx, element in enumerate(sub_arr):
            sub_arr_membership[element] = (idx, sub_arr_idx)

    for element in arr:
        idx, sub_arr_idx = sub_arr_membership[element]
        if curr_indx[idx] > sub_arr_idx:
            curr_indx[idx] = sub_arr_idx


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s