Tap here to switch tabs
Problem
Submissions

Problem: Count Pairs Whose Sum is Less than Target

Count Pairs Whose Sum is Less than Target asks you to count distinct pairs of array indexes, with the first before the second, whose values add to less than a given target. Values may be negative.

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 indexes (i,j)(i, j) such that:

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

  • The sum of the elements of the indexes (i,j)(i, j), (i.e., nums[i]+nums[j]\text{nums}[i] + \text{nums}[j]), is strictly less than the target.

Constraints:

  • n=n = nums.length

  • 1≤n≤501 \leq n\leq 50

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

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Count Pairs Whose Sum is Less than Target

Count Pairs Whose Sum is Less than Target asks you to count distinct pairs of array indexes, with the first before the second, whose values add to less than a given target. Values may be negative.

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 indexes (i,j)(i, j) such that:

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

  • The sum of the elements of the indexes (i,j)(i, j), (i.e., nums[i]+nums[j]\text{nums}[i] + \text{nums}[j]), is strictly less than the target.

Constraints:

  • n=n = nums.length

  • 1≤n≤501 \leq n\leq 50

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