Microsoft interview question

Greedy Q and Prefix sum Q