Given a **0-indexed** integer array `nums` of length `n` and an integer `target`, return *the number of pairs* `(i, j)` *where* `0 <= i < j < n` *and* `nums[i] + nums[j] < target`.
Given a 0-indexed integer array nums of length n and an integer target, return the number of pairs(i, j)where0 <= i < j < nandnums[i] + nums[j] < target.
Example 1:
Input: {"nums":[-1,1,2,3,1],"target":2}
Output: 3
Constraints:
1≤nums.length==n≤50
−50≤nums[i],target≤50
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"nums":[-1,1,2,3,1],"target":2}
Count pairs i < j with nums[i] + nums[j] < 2. Pair order does not matter, so we can sort first and count whole groups of pairs at once.