Code RoomSegment tree range assign
HardPrep Room Coding #1333

Segment tree range assign

CodingAlgorithms & data structuresSenior–Staff~40 min

Implement a segment tree over an integer array supporting two operations applied in order: ['assign', l, r, v] sets every element in the inclusive index range [l, r] to v, and ['sum', l, r] returns the sum over [l, r]. Given the initial array and the operation list, return the list of answers to the 'sum' queries in order. Use lazy propagation so each operation is O(log n).

Implement
range_assign_sum(arr: list[int], ops: list[list]) → list[int]
Examples
in[[1,2,3,4,5],[["sum",0,4],["assign",1,3,10],["sum",0,4],["sum",2,2]]]out[15,36,10]
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 40 min
InputExpectedGot
[[1,2,3,4,5],[["sum",0,4],["assign",1,3,10],["sum",0,4],["sum",2,2]]][15,36,10]not run yetsample