Explanation

557.Count Out-of-Order Pairs

Easy
Given an array nums, return how many pairs of positions i < j have nums[i] > nums[j] — pairs that appear in the wrong order compared with a sorted array. This count measures how unsorted an array is, and both solutions here are typical O(n²)Quadratic Time O(n²)Work that grows with the square of the input: doubling n makes it about four times slower. algorithms: two loops, one nested inside the other, each running up to n times. Quadratic code is fine for hundreds of values but becomes painfully slow for millions.

Example 1:

Input: nums = [3,1,2]

Output: 2

Example 2:

Input: nums = [1,2,3]

Output: 0

+ 5 hidden test cases run on Submit.

Constraints:

  • ●1 ≤ nums.length ≤ 500
  • ●-1000000 ≤ nums[i] ≤ 1000000

nums =

[3, 1, 2]