Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started