Practice Count Pairs Whose Sum is Less than Target
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Count Pairs Whose Sum is Less than Target
Problem Statement
Count pairs of distinct positions i < j whose values satisfy nums[i] + nums[j] < target. The inequality is strict, and equal values at different positions still count as separate pairs. Practice approach: At the given size limit, check all unordered pairs in O(n^2) time and O(1) extra space. An alternative is sorting and moving two pointers: when the endpoint sum is below target, every intervening partner for the left value also qualifies. Test equality with target and negative values.
Source: Count Pairs Whose Sum is Less than Target on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
nums = [-1,1,2,3,1], target = 2
3
# Example 2
nums = [-6,2,5,-2,-7,-1,3], target = -2
10
Constraints
Related LeetCode Problems
Practice more problems similar to Count Pairs Whose Sum is Less than Target.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.