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

Question

Implement a structure over an array of n zeros (indices 0..n-1) supporting range-update and point-query, each in O(log n). Process operations: ["update", l, r, v] adds v to every element in the inclusive range [l, r]; ["get", i] returns the current value at index i. Use a Fenwick tree over a difference array: a range update is two point updates (+v at l, -v at r+1) and a point query is a prefix sum. Return the list of get results in order.

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