Amazon Interview Question

2 difficult questions mainly on the segment trees and DP,