Python interview question: range sum queries
Problem
revenue is a store’s daily revenue, with days numbered from 1. Each query [first, last] in queries asks for the total from day first through day last, both included. Return the totals in query order.
def range_revenue(revenue: list[int], queries: list[list[int]]) -> list[int]:
Example
revenue = [120, 80, 150, 60, 90, 200, 40], queries = [[1, 3], [2, 5], [6, 6], [1, 7]] → [350, 380, 200, 740]days start at 1; [6, 6] is just day 6
Solve it free
Checked against hidden tests, right in your browser. No sign-up needed.
Skills it tests
More interview questions
- Python: Longest subarray with at most k distinct valuesMedium · Sliding window
- Python: Maximum average subarray of at least kHard · Binary search
- Python: Merge two sorted linked listsEasy · Linked list
- Python: Run-length encodingMedium · Arrays and strings
- Python: Top k frequent elementsMedium · Hash maps