Microsoft Interview Question

Greedy Q and Prefix sum Q