Code RoomRange update point query
MediumPrep Room Coding #1117

Range update point query

CodingDatabases & SQLAlgorithms & data structuresMid–Senior~25 min

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.

0:00 of about 25 min
InputExpectedGot
[5,[["update",1,3,2],["get",0],["get",2],["update",0,4,1],["get",2],["get",4]]][0,2,3,1]not run yetsample