Given `N`

arrays of variable length.

Find a way to concatenate the arrays in such a way that the number of inversions is minimum

An inversion for an array Arr can be defined as,

a pair of indices `(i,j)`

such that,

`i != j i < j Arr[i]>Arr[j] `

I tried to concatenate the arrays on the basis of sum, such that the one with minimal sum goes first and one with maximal sum goes last.

It didn’t work out though.

Example:-

`[14, 18, 18, 20, 16, 6, 11] SUM:- 103 [2, 4, 11, 40, 20, 14, 19] SUM:- 110 [14, 18, 18, 20, 16, 6, 11, 2, 4, 11, 40, 20, 14, 19] Inversions:- 42 [2, 4, 11, 40, 20, 14, 19, 14, 18, 18, 20, 16, 6, 11] Inversions:- 40 `