Code Room
CodingMediumcod-g062
Subject Fenwick treeLevel Mid–Senior~30 minCommon in Databases & SQL · Algorithms & data structures interviewsIndustries Software development

Question

Maintain an array of `n` integers, all initially 0, supporting two operations given in `ops` (0-indexed): `["u", l, r, delta]` adds `delta` to every element in the inclusive range [l, r], and `["q", i]` returns the current value at index i. Return the answers to the query operations in order. Both operations must run in O(log n). `1 <= n <= 100000`, `len(ops) <= 100000`.

Implement
fenwick_range_update(n: int, ops: list[list]) → list[int]
Examples
in[5,[["u",1,3,2],["q",2],["q",4]]]out[2,0]
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.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.