0

You have N lists
A = [5, 6, 10, 15]
B = [3, 0, 7, 4]
C = [49, 59, 29]
D = [19, 29, 39]
E = [9, 15, 3, 10]
You have to combine them such that:
Two lists which have a common elements they should be next to each other. In this case answer is:
A,E,B,C,D
[5, 6, 10, 15, 9, 3, 0, 7, 4, 49, 59, 29, ...