title: Maximum Sum Subarray Removing One Element
signature: fun maximumSumSubarrayRemovingOneElement(arr: ArrayList<Int>, n: Int): Int {
source_py: def maximum_sum_subarray_removing_one_element(arr, n):
      fw = [0 for k in range(n)]
      bw = [0 for k in range(n)]
      (cur_max, max_so_far) = (arr[0], arr[0])
      for i in range(n):
          cur_max = max(arr[i], (cur_max + arr[i]))
          max_so_far = max(max_so_far, cur_max)
          fw[i] = cur_max
      cur_max = max_so_far = bw[(n - 1)] = arr[(n - 1)]
      i = (n - 2)
      while (i >= 0):
          cur_max = max(arr[i], (cur_max + arr[i]))
          max_so_far = max(max_so_far, cur_max)
          bw[i] = cur_max
          i -= 1
      fans = max_so_far
      for i in range(1, (n - 1)):
          fans = max(fans, (fw[(i - 1)] + bw[(i + 1)]))
      return fans
source_cpp: int maximum_sum_subarray_removing_one_element(vector<int> arr, int n) {
    int fw [ n ], bw [ n ];
    int cur_max = arr [ 0 ], max_so_far = arr [ 0 ];
    fw [ 0 ] = arr [ 0 ];
    for ( int i = 1;
    i < n;
    i ++ ) {
      cur_max = max ( arr [ i ], cur_max + arr [ i ] );
      max_so_far = max ( max_so_far, cur_max );
      fw [ i ] = cur_max;
    }
    cur_max = max_so_far = bw [ n - 1 ] = arr [ n - 1 ];
    for ( int i = n - 2;
    i >= 0;
    i -- ) {
      cur_max = max ( arr [ i ], cur_max + arr [ i ] );
      max_so_far = max ( max_so_far, cur_max );
      bw [ i ] = cur_max;
    }
    int fans = max_so_far;
    for ( int i = 1;
    i < n - 1;
    i ++ ) fans = max ( fans, fw [ i - 1 ] + bw [ i + 1 ] );
    return fans;
  }
question_info.test_list: [{"idx": 0, "outputs": 488, "inputs": {"arr": [2, 8, 14, 17, 19, 35, 38, 45, 50, 53, 55, 70, 82, 88, 92, 96], "n": 13}}, {"idx": 1, "outputs": 344, "inputs": {"arr": [-64, -56, -80, -82, 72, 62, -8, 48, -96, 34, 64, -38, -60, 80, 4, -64, -62, 34, 94, -16, 38, 62, -84, 48, 42, -40], "n": 22}}, {"idx": 2, "outputs": 2, "inputs": {"arr": [0, 0, 0, 0, 1, 1, 1], "n": 6}}, {"idx": 3, "outputs": 424, "inputs": {"arr": [3, 7, 50, 53, 72, 14, 18, 74, 27, 65, 41, 20, 54, 17, 87, 40, 63, 15, 47], "n": 11}}, {"idx": 4, "outputs": 178, "inputs": {"arr": [-96, -96, -94, -80, -74, -74, -74, -74, -70, -64, -60, -58, -52, -52, -44, -42, -40, -38, -36, -34, -30, -14, -12, -8, -2, 6, 12, 16, 24, 24, 48, 48, 66, 76, 76, 84, 90], "n": 32}}, {"idx": 5, "outputs": 7, "inputs": {"arr": [1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0], "n": 8}}, {"idx": 6, "outputs": 1255, "inputs": {"arr": [4, 4, 5, 9, 11, 13, 13, 15, 16, 21, 23, 25, 27, 30, 31, 35, 35, 43, 43, 47, 49, 50, 52, 54, 55, 55, 57, 57, 57, 59, 62, 64, 66, 68, 69, 71, 73, 76, 80, 84, 88, 88, 90, 90, 97, 97, 99], "n": 34}}, {"idx": 7, "outputs": 482, "inputs": {"arr": [-86, -60, 4, 14, 6, -6, -50, 46, -50, -62, -56, 16, -76, 90, 40, 2, 36, 48, -26, 34, 78, 84, 2, -54, 94, 60, -26, 60, 84, 2, -98, 2, -74], "n": 25}}, {"idx": 8, "outputs": 1, "inputs": {"arr": [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1], "n": 9}}, {"idx": 9, "outputs": 646, "inputs": {"arr": [36, 99, 27, 8, 90, 74, 67, 77, 49, 23, 43, 25, 68, 56, 85, 6], "n": 12}}]
question_info.extension: kts
question_info.test_code: package main
  
  import kotlin.text.*
  import kotlin.math.*
  
  
  // SOLUTION CODE
  // ===================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE
  // ===================================
  fun validateSolution(actual:Int, expected:Int):Boolean{
    return actual.equals(expected)
  }
  fun driver(arr: ArrayList<Int>, n: Int, expected:Int):String {
      try{
        if (validateSolution(PLACEHOLDER_FN_NAME(arr, n), expected)) {
                return "PASSED"
        }
        return "FAILED"
      } catch (e: Exception){
        return e::class.simpleName as String
      }
  
  }
  
  fun main() {
      var result: String = ""
      result = driver(arrayListOf(2, 8, 14, 17, 19, 35, 38, 45, 50, 53, 55, 70, 82, 88, 92, 96), 13, 488)
      println("TEST-0...${result}")
      
      result = driver(arrayListOf(-64, -56, -80, -82, 72, 62, -8, 48, -96, 34, 64, -38, -60, 80, 4, -64, -62, 34, 94, -16, 38, 62, -84, 48, 42, -40), 22, 344)
      println("TEST-1...${result}")
      
      result = driver(arrayListOf(0, 0, 0, 0, 1, 1, 1), 6, 2)
      println("TEST-2...${result}")
      
      result = driver(arrayListOf(3, 7, 50, 53, 72, 14, 18, 74, 27, 65, 41, 20, 54, 17, 87, 40, 63, 15, 47), 11, 424)
      println("TEST-3...${result}")
      
      result = driver(arrayListOf(-96, -96, -94, -80, -74, -74, -74, -74, -70, -64, -60, -58, -52, -52, -44, -42, -40, -38, -36, -34, -30, -14, -12, -8, -2, 6, 12, 16, 24, 24, 48, 48, 66, 76, 76, 84, 90), 32, 178)
      println("TEST-4...${result}")
      
      result = driver(arrayListOf(1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0), 8, 7)
      println("TEST-5...${result}")
      
      result = driver(arrayListOf(4, 4, 5, 9, 11, 13, 13, 15, 16, 21, 23, 25, 27, 30, 31, 35, 35, 43, 43, 47, 49, 50, 52, 54, 55, 55, 57, 57, 57, 59, 62, 64, 66, 68, 69, 71, 73, 76, 80, 84, 88, 88, 90, 90, 97, 97, 99), 34, 1255)
      println("TEST-6...${result}")
      
      result = driver(arrayListOf(-86, -60, 4, 14, 6, -6, -50, 46, -50, -62, -56, 16, -76, 90, 40, 2, 36, 48, -26, 34, 78, 84, 2, -54, 94, 60, -26, 60, 84, 2, -98, 2, -74), 25, 482)
      println("TEST-7...${result}")
      
      result = driver(arrayListOf(0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1), 9, 1)
      println("TEST-8...${result}")
      
      result = driver(arrayListOf(36, 99, 27, 8, 90, 74, 67, 77, 49, 23, 43, 25, 68, 56, 85, 6), 12, 646)
      println("TEST-9...${result}")
      
          
  }
  
  main()
question_info.entry_fn_name: maximumSumSubarrayRemovingOneElement
question_info.entry_cls_name: Solution
question_info.test_case_ids: 0 1 2 3 4 5 6 7 8 9
question_info.commands: kotlinc -script __FILENAME__ -no-reflect -nowarn