Amazon Interview Question

Based on prefix sum that we see on leetcode.