Want to solve this problem? Login now to get access to solve the problems
You do not need to print anything, just return the inversion count for the given linked list.
The first and the only line of the input contains the elements of the singly linked list separated by a single space and terminated by -1. Hence, -1 would never be a list element.
A single integer denoting the inversion count of the given list.
0 <= L <= 10^5
-10^9 <= data <= 10^9 and data != -1
Where L is the number of nodes in the linked list.
3 2 1 5 4 -1
4
For the given linked list, there are 4 inversions: (3, 2), (3, 1), (2, 1) and (5, 4). Thus, the inversion count is 4.
0 6 8 7 -1
1