Count queries below sum limit
Given a list of integers, a batch of queries, and an integer limit, count how many queries select a range whose sum is strictly below the limit. Each query is a pair [l, r] with 0 <= l <= r < n, selecting elements l through r inclusive. Return the number of qualifying queries. Values may be negative. Example: values = [8, 2, 5, 1], queries = [[0, 1], [1, 3], [2, 3]], limit = 9 gives 2 — the range sums are 10, 8, and 6.
Implement
count_below_limit(values: list[int], queries: list[list[int]], limit: int) → intExamples
in
[[8,2,5,1],[[0,1],[1,3],[2,3]],9]out2What 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 11 min
solution.py
InputExpectedGot
[[8,2,5,1],[[0,1],[1,3],[2,3]],9]2not run yetsample