title: Largest Sum Contiguous Subarray 2
signature: class Solution {
  
      public Integer largestSumContiguousSubarray2(ArrayList<Integer> a, Integer size) {
source_py: def largest_sum_contiguous_subarray_2(a, size):
      max_so_far = a[0]
      curr_max = a[0]
      for i in range(1, size):
          curr_max = max(a[i], (curr_max + a[i]))
          max_so_far = max(max_so_far, curr_max)
      return max_so_far
source_cpp: int largest_sum_contiguous_subarray_2(vector<int> a, int size) {
    int max_so_far = a [ 0 ];
    int curr_max = a [ 0 ];
    for ( int i = 1;
    i < size;
    i ++ ) {
      curr_max = max ( a [ i ], curr_max + a [ i ] );
      max_so_far = max ( max_so_far, curr_max );
    }
    return max_so_far;
  }
question_info.extension: java
question_info.entry_fn_name: largestSumContiguousSubarray2
question_info.entry_cls_name: Solution
question_info.test_list: [{"idx": 0, "outputs": 1265, "inputs": {"a": [1, 3, 4, 7, 8, 8, 10, 12, 16, 19, 19, 20, 20, 21, 21, 22, 26, 27, 29, 34, 36, 38, 38, 39, 41, 43, 44, 47, 47, 49, 57, 57, 60, 62, 63, 65, 75, 77, 77, 78, 81, 82, 82, 83, 83, 84, 85, 98, 99], "size": 38}}, {"idx": 1, "outputs": 90, "inputs": {"a": [-40, 14, 2, -70, 86, -90, -50, -54, -2, 90, 30], "size": 10}}, {"idx": 2, "outputs": 11, "inputs": {"a": [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], "size": 18}}, {"idx": 3, "outputs": 1063, "inputs": {"a": [60, 69, 41, 7, 77, 36, 36, 26, 35, 30, 64, 75, 3, 35, 60, 71, 29, 47, 15, 29, 43, 88, 56, 22, 9, 45, 40, 50, 52], "size": 25}}, {"idx": 4, "outputs": 348, "inputs": {"a": [-96, -88, -80, -72, -64, -64, -60, -60, -60, -58, -56, -54, -54, -50, -50, -26, -26, -24, -20, -8, -2, 0, 4, 4, 12, 14, 18, 18, 24, 32, 42, 44, 44, 44, 48, 50, 50, 56, 60, 60, 70, 80, 88, 88, 90, 98], "size": 35}}, {"idx": 5, "outputs": 13, "inputs": {"a": [0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0], "size": 22}}, {"idx": 6, "outputs": 1306, "inputs": {"a": [2, 4, 4, 5, 6, 7, 11, 12, 14, 18, 23, 24, 27, 28, 33, 36, 37, 38, 39, 40, 41, 41, 48, 48, 52, 61, 64, 66, 66, 77, 79, 82, 85, 88, 91, 94, 99], "size": 34}}, {"idx": 7, "outputs": 172, "inputs": {"a": [-56, 0, 16, 12, 20, 36, 32, -52, -68, -36, -96, -46, -34, 56, 2, 78, 6, 30, -68, -48, 2, 44, -26, -36, -30, -20, -90, -66, 4, 94, 8, 4, -4, -32, -24], "size": 20}}, {"idx": 8, "outputs": 10, "inputs": {"a": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], "size": 22}}, {"idx": 9, "outputs": 1019, "inputs": {"a": [39, 87, 27, 89, 26, 25, 80, 82, 21, 25, 55, 27, 20, 81, 47, 79, 26, 72, 10, 11, 90, 89], "size": 21}}]
question_info.test_code: import static java.util.Map.entry;  
  import java.util.*;
  import java.lang.*;
  // TESTING CODE 
  // ============================================
  class QuestionEvaluator {
      public static String validateSolution(ArrayList<Integer> a, Integer size, Integer expected){
          try{
              Driver driver = new Driver();
              if (driver.run(a, size,expected)){
                  return "PASSED";
              }
              return "FAILED";
              
          } catch (Exception exception_obj){
              return exception_obj.getClass().getSimpleName();
          }
  
      }
      public static void main(String[] args) {
          String result;
          result = validateSolution(new ArrayList<>(Arrays.asList(1, 3, 4, 7, 8, 8, 10, 12, 16, 19, 19, 20, 20, 21, 21, 22, 26, 27, 29, 34, 36, 38, 38, 39, 41, 43, 44, 47, 47, 49, 57, 57, 60, 62, 63, 65, 75, 77, 77, 78, 81, 82, 82, 83, 83, 84, 85, 98, 99)), 38, 1265);
          System.out.println(String.format("%s%s","TEST-0...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(-40, 14, 2, -70, 86, -90, -50, -54, -2, 90, 30)), 10, 90);
          System.out.println(String.format("%s%s","TEST-1...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)), 18, 11);
          System.out.println(String.format("%s%s","TEST-2...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(60, 69, 41, 7, 77, 36, 36, 26, 35, 30, 64, 75, 3, 35, 60, 71, 29, 47, 15, 29, 43, 88, 56, 22, 9, 45, 40, 50, 52)), 25, 1063);
          System.out.println(String.format("%s%s","TEST-3...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(-96, -88, -80, -72, -64, -64, -60, -60, -60, -58, -56, -54, -54, -50, -50, -26, -26, -24, -20, -8, -2, 0, 4, 4, 12, 14, 18, 18, 24, 32, 42, 44, 44, 44, 48, 50, 50, 56, 60, 60, 70, 80, 88, 88, 90, 98)), 35, 348);
          System.out.println(String.format("%s%s","TEST-4...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0)), 22, 13);
          System.out.println(String.format("%s%s","TEST-5...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(2, 4, 4, 5, 6, 7, 11, 12, 14, 18, 23, 24, 27, 28, 33, 36, 37, 38, 39, 40, 41, 41, 48, 48, 52, 61, 64, 66, 66, 77, 79, 82, 85, 88, 91, 94, 99)), 34, 1306);
          System.out.println(String.format("%s%s","TEST-6...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(-56, 0, 16, 12, 20, 36, 32, -52, -68, -36, -96, -46, -34, 56, 2, 78, 6, 30, -68, -48, 2, 44, -26, -36, -30, -20, -90, -66, 4, 94, 8, 4, -4, -32, -24)), 20, 172);
          System.out.println(String.format("%s%s","TEST-7...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)), 22, 10);
          System.out.println(String.format("%s%s","TEST-8...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(39, 87, 27, 89, 26, 25, 80, 82, 21, 25, 55, 27, 20, 81, 47, 79, 26, 72, 10, 11, 90, 89)), 21, 1019);
          System.out.println(String.format("%s%s","TEST-9...",result));    
      
      }
  }
  
  class Driver{
      public boolean run(ArrayList<Integer> a, Integer size, Integer expected){
  
          PLACEHOLDER_CLS_NAME sol = new PLACEHOLDER_CLS_NAME();
          return validateSolution(sol.PLACEHOLDER_FN_NAME(a, size),expected);
      }
      
      public boolean validateSolution(Integer actual, Integer expected){
          return actual.equals(expected);
      }
  }
  
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
question_info.test_case_ids: 0 1 2 3 4 5 6 7 8 9
question_info.commands: java __FILENAME__