title: Minimum Sum Two Numbers Formed Digits Array 2
signature: function minimum_sum_two_numbers_formed_digits_array_2(a, n)
source_py: def minimum_sum_two_numbers_formed_digits_array_2(a, n):
      a = sorted(a)
      (num1, num2) = (0, 0)
      for i in range(n):
          if ((i % 2) == 0):
              num1 = ((num1 * 10) + a[i])
          else:
              num2 = ((num2 * 10) + a[i])
      return (num2 + num1)
source_cpp: int minimum_sum_two_numbers_formed_digits_array_2(vector<int> a, int n) {
    sort(a.begin(), a.end());
    int num1 = 0;
    int num2 = 0;
    for ( int i = 0;
    i < n;
    i ++ ) {
      if ( i % 2 == 0 ) num1 = num1 * 10 + a [ i ];
      else num2 = num2 * 10 + a [ i ];
    }
    return num2 + num1;
  }
question_info.test_code: 
  
  -- SOLUTION CODE
  -- ============================================
  PLACEHOLDER_CODE_BODY
  
  -- TESTING CODE 
  -- ============================================
  function isCorrect(actual, expected)
      if type(expected) ~= type(actual) then
          return false
      end
      
      if type(expected) == 'table' then
          for k,v_expected in pairs(expected) do
              
              if actual[k] == nil then
                  return false
              end
              local v_actual = actual[k]
              if not isCorrect(v_actual, v_expected) then
                  return false
              end
              actual[k]=nil
          end
      
          if next(actual) then 
              return false
          end
          return true
      else
          return actual == expected
      end
  end
  
  function validateSolution(actual, expected)
      return isCorrect(actual,expected)
  end
  
  function driver(a, n, expected)
      local exec_result;
      local status, error_msg = pcall(function () 
          exec_result=PLACEHOLDER_FN_NAME(a, n) 
      end)
      if status then
          if validateSolution(exec_result,expected) then
              return "PASSED"
          end
          return "FAILED"
      else
          return string.format("ERROR=%s",string.gsub(error_msg,".*:[%d]+: ",""))
      end
  end
      
  function main()
      result = driver({4, 16, 29, 30, 38, 83}, 5, 918)
      print(string.format("TEST-0...%s",result))
  
      result = driver({58, 74, -28, -60, -6, 66, -76, 46, 0, -24, 28, -16, -14, 24, -94, -56, -80, 40, -18, -68, -8, -94, -88, -12, -20, -8}, 16, -2063616120)
      print(string.format("TEST-1...%s",result))
  
      result = driver({0, 1}, 1, 0)
      print(string.format("TEST-2...%s",result))
  
      result = driver({7, 12, 78, 8}, 3, 90)
      print(string.format("TEST-3...%s",result))
  
      result = driver({-78, -48, -48, -26, 8, 34}, 4, -1334)
      print(string.format("TEST-4...%s",result))
  
      result = driver({1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0}, 27, 2222222)
      print(string.format("TEST-5...%s",result))
  
      result = driver({2, 3, 5, 7, 25, 30, 31, 38, 42, 45, 52, 53, 56, 59, 60, 71, 74, 76, 80, 90, 91, 98}, 13, 3190079)
      print(string.format("TEST-6...%s",result))
  
      result = driver({0, 0, 0, 0, 0, 0, 1, 1, 1}, 8, 2)
      print(string.format("TEST-7...%s",result))
  
      result = driver({59, 9, 3, 20, 83, 87, 48, 4, 86, 67, 89, 96, 17, 36, 39, 45, 99, 8, 56, 92, 63, 81, 7, 75, 32, 10, 71, 82, 97, 92, 65, 23, 22, 47, 70, 79, 57, 81, 65, 50}, 35, 430183530665338166)
      print(string.format("TEST-8...%s",result))
  
  end
  
  main()
question_info.entry_cls_name: Solution
question_info.test_list: [{"idx": 0, "outputs": 918, "inputs": {"a": [4, 16, 29, 30, 38, 83], "n": 5}}, {"idx": 1, "outputs": -2063616120, "inputs": {"a": [58, 74, -28, -60, -6, 66, -76, 46, 0, -24, 28, -16, -14, 24, -94, -56, -80, 40, -18, -68, -8, -94, -88, -12, -20, -8], "n": 16}}, {"idx": 2, "outputs": 0, "inputs": {"a": [0, 1], "n": 1}}, {"idx": 3, "outputs": 90, "inputs": {"a": [7, 12, 78, 8], "n": 3}}, {"idx": 4, "outputs": -1334, "inputs": {"a": [-78, -48, -48, -26, 8, 34], "n": 4}}, {"idx": 5, "outputs": 2222222, "inputs": {"a": [1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0], "n": 27}}, {"idx": 6, "outputs": 3190079, "inputs": {"a": [2, 3, 5, 7, 25, 30, 31, 38, 42, 45, 52, 53, 56, 59, 60, 71, 74, 76, 80, 90, 91, 98], "n": 13}}, {"idx": 7, "outputs": 2, "inputs": {"a": [0, 0, 0, 0, 0, 0, 1, 1, 1], "n": 8}}, {"idx": 8, "outputs": 430183530665338166, "inputs": {"a": [59, 9, 3, 20, 83, 87, 48, 4, 86, 67, 89, 96, 17, 36, 39, 45, 99, 8, 56, 92, 63, 81, 7, 75, 32, 10, 71, 82, 97, 92, 65, 23, 22, 47, 70, 79, 57, 81, 65, 50], "n": 35}}]
question_info.extension: lua
question_info.entry_fn_name: minimum_sum_two_numbers_formed_digits_array_2
question_info.test_case_ids: 0 1 2 3 4 5 6 7 8
question_info.commands: lua __FILENAME__