Company: Amazon off campus sde1_24march
Difficulty: medium
In this problem, you are given an integer array and you need to perform some adjustments on the array to make all the elements equal to 0. In one adjustment, you can select a prefix of the given array and increase or decrease all the elements of the prefix by 1. You have an array, values, consisting of n integers. Find the minimum number of adjustments required to convert every element of this array to 0. A prefix is a contiguous group of items that includes the first element in the inventory. For example, [1], [1, 2], [1, 2, 3] etc are prefixes of [1, 2, 3, 4, 5]. Note: It is guaranteed that it is always possible to convert every element of the array to 0. Example values = [3, 2, 1] The most efficient approach is: Adjustment 1: Let the prefix length be 2, and decrease by 1. inventory after this adjustment is [2, 1, 1]. Adjustment 2: Let the prefix length be 1, and decrease by 1. inventory after this adjustment is [1, 1, 1]. Adjustment 3: Let the prefix length be 3, and decrease by 1.