Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Would it be easier to count the number of pairs that are not bad pairs?
Notice that (j - i != nums[j] - nums[i]) is the same as (nums[i] - i != nums[j] - j).
Keep a counter of nums[i] - i. To be efficient, use a HashMap.