shlogg · Early preview
Md Ariful Haque @mah-shamim

Counting Bad Pairs In An Array

Count bad pairs in array nums by calculating total pairs (n*(n-1)/2) and subtracting good pairs (sum of m*(m-1)/2 for each group with m elements). Use a frequency map to count occurrences of each value (nums[i] - i).

2364. Count Number of Bad Pairs
Difficulty: Medium
Topics: Array, Hash Table, Math, Counting
You are given a 0-indexed integer array nums. A pair of indices (i, j) is a bad pair if i < j and j - i != nums[j] - nums[i].
Return the total number of bad pairs in nums.
Example 1:

Input: nums = [4,1,3,3]
Output: 5
Explanation: 

The pair (0, 1) is a bad pair since 1 - 0 != 1 - 4.
The pair (0, 2) is a bad pair since 2 - 0 != 3 - 4, 2 != -1.
The pair (0, 3) is a bad pair since 3 - 0 != 3 - 4, 3 != -1.
The pair (1, 2) is a bad pair since 2 - 1 != 3 - 1, 1 != 2.
The pair (2, 3) is a bad pair since 3 -...