Given an integer array, count the total number of triplets, which leads to an inversion. If (i < j < k) and (nums[i] > nums[j] > nums[k]), then the triplet (i, j, k) has formed an inversion in array `nums`.
int nums[] = {9, 6, 4, 5, 8}; int count = 0; for (int i = 0; i < nums.length; i++) { for (int j = i + 1; j < nums.length; j++) { for (int k = j + 1; k < nums.length; k++) { if (nums[i] > nums[j] && nums[j] > nums[k]) { count++; } } } } return count;