Light intensity pairs

Write codeMedium14 min

Your task

A gym app pairs members for partner workouts and lists session intensities sorted ascending. A pairing is "light" if the two intensities sum to strictly less than a limit. Given the sorted list intensities and the limit, return how many unordered pairs (i < j) are light. Do it in O(n) with converging pointers, when the current pair is light, notice how many pairs that observation settles at once. Example: [100, 200, 300, 400] with limit 500 gives 2.

Examples

count_light_pairs(intensities: list[int], limit: int) -> int
Example 1
Inputcount_light_pairs([100, 200, 300, 400], 500)
Output2