101
0/320
Loading content...
You are given an integer array nums containing n elements (0-indexed) and an integer threshold. Your task is to determine how many index pairs (i, j) exist such that:
0 ≤ i < j < nnums[i] + nums[j] < thresholdReturn the total count of all such valid pairs that satisfy both conditions.
Key Observations:
(i, j) is valid, we do not also count (j, i) because we require i < j.nums = [-1,1,2,3,1]
threshold = 23There are 3 pairs of indices that satisfy both conditions:
nums = [-6,2,5,-2,-7,-1,3]
threshold = -210There are 10 pairs whose sum is strictly below -2:
nums = [1,2,3,4,5]
threshold = 52Only 2 pairs have sums strictly below the threshold of 5:
Constraints