18. Count Inversions
β GFG solution to the Count Inversions problem: find the number of inversion pairs in an array using merge sort, BIT, and segment tree techniques. π
π§© Problem Description
π Examples
Example 1
Input: arr[] = [2, 4, 1, 3, 5]
Output: 3
Explanation: The sequence 2, 4, 1, 3, 5 has three inversions: (2, 1), (4, 1), (4, 3).Example 2
Input: arr[] = [2, 3, 4, 5, 6]
Output: 0
Explanation: The sequence is already sorted, so there is no inversion count.Example 3
π Constraints
β
My Approach
Modified Merge Sort
π Time and Auxiliary Space Complexity
π§βπ» Code (C)
π§βπ» Code (C++)
β Code (Java)
π Code (Python)
π§ Contribution and Support
πVisitor Count
Last updated