Segment trees and range queries

What is the new sum at the root?

Examples

Worked example

Input
[2, 4, 1, 8]. Change index 1 from 4 to 7.
Expected output
18

Hints and solution

Hint 1

Write down the starting state and walk through one example by hand.

Reveal worked answer

The left child changes from 6 to 9. The right child stays 9. The root combines them to get 18.

Back to the lesson