FunctionRacerProblemsRace

Count Pairs Below Target

EasyTwo pointersPython, JavaScript, TypeScript, Java, C++

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

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Two pointers problems