- Arrays, Reverse

Maximize sum of elements at corresponding indices of given array and its reversed array

Given an array arr[] containing N integers, the task is to find the maximum sum obtained by adding the elements at the same index of the original array and of the reversed array.Example:Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.  To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.In case you wish to attend live classes with experts, please refer DSA Live Classes for Working Professionals and Competitive Programming Live for Students.Input: arr[]={ 1, 8, 9, 5, 4, 6 }Output: 14Explaination: Original array : {1, 8, 9, 5, 4, 6}Reversed array: {6, 4, 5, 9, 8, 1}Adding corresponding indexes element:{1+6=7, 8+4=12, 9+5=14, 5+9=14, 4+8=12, 6+1=7}So, The Maximum sum is 14.Input: arr[]={-31, 5, -1, 7, -5}Output: 12Naive approach: Create a reversed array and return the maximum sum after adding corresponding index elements. Maximum sum after adding the corresponding reversed array elementBelow is the implementation of the above approach C++  #include using namespace std;  int maximumSum(int arr[], int n){    int c = 0;          int reversed[n];      for (int i = n – 1; i >= 0; i–)        reversed[c++] = arr[i];      int res = INT_MIN;                  for (int i = 0; i < n; i++) {        res = std::max(res,                       arr[i] + reversed[i]);    }    return res;}  int main(){    int arr[] = { 1, 8, 9, 5, 4, 6 };    int n = sizeof(arr) / sizeof(arr[0]);      cout