Amazon interview question

Segment tree - LeetCode medium Asked to code brute force first and then the optimised solution.