Count Pairs Below Target
Count the pairs of positions (i, j) of the list nums with i < j such that nums[i] + nums[j] < target (strictly less than the number target).
Example 1
nums [-1,1,2,3,1]
target 2
returns 3
The pairs -1 with 1, -1 with 2, and -1 with the last 1 add to 0, 1 and 0. No other pair adds to less than 2, so 3.
Constraints
1 <= len(nums) <= 30-20 <= nums[i], target <= 40
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.