Count Number of Bad Pairs

Implement countBadPairs

A pair of indices (i, j) with i < j is called bad when the gap between the indices doesn't match the gap between the values at those indices — that is, j - i ≠ nums[j] - nums[i]. Count how many bad pairs exist among all pairs of indices in the array.

Example 1:

Input: nums = [2,3,4,7,10]

Output: 7

Example 2:

Input: nums = [5,5,5,5]

Output: 6

Example 3:

Input: nums = [1,2]

Output: 0

+ 6 hidden test cases run on Submit.

Constraints:

  • 1 ≤ nums.length ≤ 10
  • -100 ≤ nums[i] ≤ 100

nums =

[2, 3, 4, 7, 10]