Ctrl K

Pairs Below the Limit

Easy
A sensor produced a series of readings readings — integers that may be negative. An engineer wants to know which two readings together stay under the threshold limit. Return the number of index pairs i < j where readings[i] + readings[j] is strictly less than limit.
Example 1
readings=[3, -2, 0, 4], limit=2 → 2

The pairs 3 + (−2) = 1 and (−2) + 0 = −2 qualify; (−2) + 4 = 2 does not, since 2 is not below 2. That makes two pairs.

Example 2
readings=[1, 1, 1], limit=3 → 3

Any two readings sum to 2 < 3, and there are three pairs.

Example 3
readings=[-5, 10], limit=-10 → 0

The only pair sums to 5, which is not below −10.

Constraints
  • 1 ≤ len(readings) ≤ 50
  • −100 ≤ readings[i] ≤ 100
  • −200 ≤ limit ≤ 200
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsValues in Both Lists EasyShared Values With Repeats EasyBest Pair Under the Limit EasyTwice as Much EasyFar From Every Mark Easy
loading Python…
Input
readings=[3, -2, 0, 4], limit=2
Expected
2

Run checks the first 3 tests in your browser. Submit checks all 111 tests on the server, hidden ones included.