Question: Question 2 From an array source of n integers, in a single ALL operation, choose any even - length subarray. Alternately add and subtract 1

Question 2
From an array source of n integers, in a single ALL operation, choose any even-length subarray. Alternately add and subtract 1 from each element of the subarray from left to right. For example, for source =[1,2,3,4,5,6] the subarray 3,4,5,6 can be chosen and made ,6,5. Then source =[1,2,4,3,6,5].
Given two arrays source and target of n integers, find the minimum number of operations that must be performed on the array source to make it equal to the array targeh Report -1 if it is not possible to make the two arrays equal.
Example
Suppose n=4, source =[4,3,1,3], and target ,2,3,0
It is optimal to choose the subarray 3,1 and get source =[4,4,0,3]. Now choose 0,3 to get source =[4,4,1,2]. Now choose the entire array to get source =[5,3,2,1]. Finally choose 5,1 to get source =[6,2,3,0]. Thus the two arrays can be equalized in at most 4 operations. Hence the answer is 4.
Function Description
Complete the function getMinOperations in the editar helois
 Question 2 From an array source of n integers, in a

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!