Make Power Non-decreasing
MediumAsked in:Amazon•Stage:Online Assessment
arraygreedy
Problem Statement
Given an array of integers representing the power of n devices, you may increase the power of any device by any non‑negative amount. Determine the minimum total amount of power that must be added so that the power levels become a non‑decreasing sequence (i.e., each element is at least as large as the previous one).
Input Format
The first line contains an integer n, the number of devices. The second line contains n space‑separated integers power[1],…,power[n] representing the initial power of each device.
Output Format
Output a single integer – the minimum total increment required to make the power array non‑decreasing.
Constraints
- 1 <= n <= 10^5
- -10^9 <= power[i] <= 10^9