Code Room
CodingHardcod-g769
Subject Segment treeLevel Senior–Staff~40 minCommon in Algorithms & data structures interviewsIndustries Software development, Technology

Question

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.

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.