Find the maximum possible summation of differences of consecutive elements
The above can be optimized by using two things.


Memorizing the result of the func().  To implement memorizing you need to send some response from the func which can be memorized for certain parameters. In your cases it wouldn't be possible. You need to change the func defination to implement memorizing.  
Pre-processing on array B to calculate minimum till any i and maximum till any i. 



  Explaining 2nd point in detail, at any point of three possible
  combination of \$A_{i-1}, A_i\$ and \$A_{i+1}\$ 
  
  \$A_i &gt; A_{i-1}, A_{i+1}\$, In this case it makes sense to choose \$A_i\$ as the max value in B till i
  
  \$A_i &lt; A_{i-1},A_{i+1}\$, In this case it makes sense to choose \$A_i\$ as the min value in B till i
  
  \$A_{i-1} &lt; A_i &lt; A_{i+1}\$, In this case you can see \$A_i\$ would have any involvement in final sum. It is getting cancelled out. So even if we choose \$A_{i-1}\$ or \$A_{i+1}\$ as \$A_i\$ it will also give same result. 
  Hence it makes sense to pick either min or max value at any point from B. 


You can try below solution with both of the above optimization. 

possible_sum[][] = new Integer[n][2] // An array which memorize maximum possible sum till any n
initially possible_sum to some default value '-1'

int find_possible_sum(int i, int next, int minORmax){
    if(possible_sum[i][minORmax] != -1)return possible_sum[i][minORmax];
    possible_sum[i][minORmax] =  max(find_possible_sum(i-1, max_till_i, 0) + abs(max_till_i - next), find_possible_sum(i-1, minTill_i, 1)) + abs(min_till_i - next)); 
   // max_till_i and min_till_i can obtained in O(n) during pre-calculation
   return possible_sum[i][minORmax];
}




int max_value = -1 , min_value = MAX_VALUE;
   int min_till_i[], max_till_i[]; 
   for(int i=1;i&lt;=n;i++){
        min_till_i[i] = min(B[i],min_value);
        min_value = min(min_value, B[i]);

        max_till_i[i] = max(B[i],max_value);
        max_value = min(max_value, B[i]);
    }


Total complexility of this solution should be around: \$O(n)\$ + \$O(2*n)\$