Count balanced pairs
A review site collects integer scores for a film, one per reviewer, in submission order. The editors call two reviewers a "balanced pair" when their scores add up to exactly target. Given the score list and the target, count the number of unordered reviewer pairs (i, j) with i < j whose scores sum to target. Every index pair counts even when the values are equal. For example, scores [3, 7, 5, 5, 7] with target 10 contain three balanced pairs: the 3 with each 7, and the two 5s together. Aim for a single pass.
Implement
rating_pairs(ratings: list[int], target: int) → intExamples
in
[[3,7,5,5,7],10]out3What a strong answer looks like
State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
0:00 of about 14 min
solution.py
InputExpectedGot
[[3,7,5,5,7],10]3not run yetsample