Count Pairs Whose Sum is Less than Target
The function countPairs
returns the number of pairs (i, j)
where 0 <= i < j < n
and nums[i] + nums[j] < target
.
|
|
Explanation
- We iterate through all possible pairs of elements
(i, j)
wherei < j
. - We check if the sum of the current pair is less than the given target.
- If the condition is met, we increment the count of such pairs.
- The function returns the final count, representing the number of pairs that meet the given condition.