Code RoomCount queries below sum limit
EasyPrep Room Coding #481

Count queries below sum limit

CodingDatabases & SQLAlgorithms & data structuresEntry–Mid~11 min

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) → int
Examples
in[[8,2,5,1],[[0,1],[1,3],[2,3]],9]out2
What 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
InputExpectedGot
[[8,2,5,1],[[0,1],[1,3],[2,3]],9]2not run yetsample