Question: Modify an Array the minimum cost to sort the array either ascending or descending along its length. Example n = 6 arr = [ 0
Modify an Array
the minimum cost to sort the array either ascending or descending along its length.
Example
arr
Only arr violates the order for an ascending sort.
If the value is increased to the array will be sorted in ascending order. arr'
The cost is arr
Function Description
Complete the modifyArray function in the editor below.
long modifyArrayvector arr
modifyArray has the following parameters:
int arrn: an array of integers
Returns
long int: an integer that denotes the minimum cost required to make the array ascending nondecreasing or descending nonincreasing along its length.
Constraints
arn
V Input Format for Custom Testing
Input from stdin will be processed as follows and passed to the function.
The first line contains the integer the number of elements in arr.
The next lines each contain an integer, arrij
Sample Case
Sample Input
STDIN Function
arr size
arr
Sample Output
Explanation
Only arr violates the array descending order.
If the value is increased to the array will be sorted in descending order:
The minimum cost to sort it in descending order is arr
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
