Gamified challenge · Prefix sums
mines[k] is the gold in mine k along the valley. Each query [i, j] in queries asks how much gold lies in mines i to j, both included (0-based, i <= j).
Write rangeGold(mines, queries) (range_gold in Python) that returns one total per query, in the same order. There can be many queries, so build a running total once instead of re-adding every range.
For mines = [3, 1, 4, 1, 5, 9, 2, 6] and queries = [[0, 3], [2, 5], [4, 4]] the answer is [9, 19, 5].
This game is part of the paid plans. Sign in, then pick a plan to write your answer, watch it play out, and step through the algorithm with its guide.
Sign in with Google