Amazon Coding Question – Solved

2 Live
In this problem, you are given an integer array, and you need to perform some operations on the array to make all the elements equal to 0. In one operation, you can select a prefix of the given array and increment or decrement all the elements of the prefix by 1. You have an array, arr, consisting of n integers. Find the minimum number of operations 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 array. 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: arr = [3, 2, 1]

Asked in: Amazon

Image of the Question

Question Image

All Testcases Passed βœ”



Passcode Image

Solution


Please login to view the solution


Related Questions

| Given an n x m grid, where rows are numbered from 7 to n and columns from 1 to … |
| There are 'N' coders standing in a line, where i denotes the ith position of a … |
| A birthday party was attended by N number of kids, and each kid was given a uni… |
| Given a matrix of size m * n, where m denotes the number of rows (starting with… |
| A traveler is traveling from the city of Zeta to Omega. He starts with X amount… |
| As an operations engineer at Amazon, you are responsible for organizing the dis… |