Count Pairs Whose Sum is Less than Target

Try to solve the Count Pairs Whose Sum is Less than Target problem.

Statement

You are given a 0-indexed integer array, nums, of length nn, and an integer target. Your task is to determine the number of distinct pairs of indices (i,j)(i, j) such that:

  • 0i<j<n0 \leq i < j < n (i.e., ii comes before jj in the array)

  • The sum of the elements of the indices (i,j)(i, j), (i.e., nums[i]+nums[j]nums[i]+nums[j]), is strictly less than target.

Constraints:

  • 11 \leq nums.length ==== n50n\leq 50

  • 50-50 \leq nums[i], target 50\leq 50

Examples

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.