Created
          February 3, 2020 06:32 
        
      - 
      
- 
        Save anhnguyen1618/a490ac6db486b065b1a8624fb8a2ae86 to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import java.io.*; | |
| import java.math.*; | |
| import java.security.*; | |
| import java.text.*; | |
| import java.util.*; | |
| import java.util.concurrent.*; | |
| import java.util.function.*; | |
| import java.util.regex.*; | |
| import java.util.stream.*; | |
| import static java.util.stream.Collectors.joining; | |
| import static java.util.stream.Collectors.toList; | |
| class Result { | |
| public static long computeSum(List<Integer> integerArray) { | |
| int sum = 0; | |
| for (int i: integerArray) sum += i; | |
| return sum; | |
| } | |
| /* | |
| * Complete the 'getMaximumScore' function below. | |
| * | |
| * The function is expected to return a LONG_INTEGER. | |
| * The function accepts INTEGER_ARRAY integerArray as parameter. | |
| */ | |
| public static long getMaximumScore(List<Integer> integerArray) { | |
| System.out.println(integerArray); | |
| int left = 0; | |
| int right = integerArray.size()-1; | |
| long sum = computeSum(integerArray); | |
| return compute(integerArray, left, right, 1, sum, 0); | |
| // Write your code here | |
| } | |
| public static long compute(List<Integer> integerArray, int left, int right, int counter, long sum, long result) { | |
| if (left > right) return 0; | |
| if (left == right) { | |
| if (counter % 2 == 0) { | |
| return result - sum; | |
| } else { | |
| return result + sum; | |
| } | |
| } | |
| if (counter % 2 == 0) { | |
| long leftResult = compute(integerArray, left +1, right, counter +1, sum - integerArray.get(left), result - sum); | |
| long rightResult = compute(integerArray, left, right-1, counter +1, sum - integerArray.get(right), result - sum); | |
| return Math.max(leftResult, rightResult); | |
| } | |
| long leftResult = compute(integerArray, left +1, right, counter +1, sum - integerArray.get(left), result + sum); | |
| long rightResult = compute(integerArray, left, right-1, counter +1, sum - integerArray.get(right), result + sum); | |
| return Math.max(leftResult, rightResult); | |
| } | |
| } | |
| public class Solution { | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment