We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Merge Sort: Counting Inversions
- Discussions
Merge Sort: Counting Inversions
Merge Sort: Counting Inversions
Sort by
recency
|
507 Discussions
|
Please Login in order to post a comment
Java Solution
O(n log(n))
C++ solution. Solving this by merge sort is probably the quickest way, as it is done in O(nlogn) time, as opposed to other methods most of which run in O(n^2).
An addition to the merge sort algorithm made specifically for this question is that we need to keep track of the number of swaps made in the algorithm.
For people looking for PHP solution. You can use the merge sort procedure to solve this
Python3 My Solution