Title Description:
Given an integer array of length N (n>1), a can be divided into two parts, left part A[0..K],
The right portion of the a[k+1..n-1],k can be evaluated in the range [0,n-2].
In so many partitioning schemes, the largest value in the left part minus the absolute value of the right part maximum, what is the maximum?
Given the integer array A and the size of the group N, return the answer to the question you asked.
Test examples:
[2,7,3,1,1],5
Returns: 6
1#include <iostream>2#include <vector>3 using namespacestd;4 5 intFindmaxgap (vector<int> A,intN) {6 intmax = a[0];7 for(inti =0; I < n; i++)8 if(A[i] >max)9Max =A[i];Ten intMinux = a[0] > a[n-1] ? a[n-1]: a[0]; One returnMax-Minux; A } - - intMain () { thevector<int>A; -A.push_back (2); -A.push_back (7); -A.push_back (3); +A.push_back (4); -A.push_back (1); +A.push_back (1); A //A.push_back (1); at //A.push_back (2); - //A.push_back (3); - //A.push_back (3); - //A.push_back (8); - //A.push_back (9); -cout << Findmaxgap (A,6) <<Endl; in return 0; -}
2-2-Maximum difference between the left and right values