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.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.
readings=[1, 1, 1], limit=3 → 3
Any two readings sum to 2 < 3, and there are three pairs.
readings=[-5, 10], limit=-10 → 0
The only pair sums to 5, which is not below −10.
readings=[3, -2, 0, 4], limit=2
2
Run checks the first 3 tests in your browser. Submit checks all 111 tests on the server, hidden ones included.