title: Minimum Sum Two Numbers Formed Digits Array 2
signature: class Solution {
  
      public long MinimumSumTwoNumbersFormedDigitsArray2(List<int> a, int n) {
test_code: using System;
  using System.Numerics;
  using System.Diagnostics;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Security.Cryptography;
  using System.Web.UI;
  using System.Web.Script.Serialization;
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  namespace EvaluatePrediction {
      class TestRunner {
          public bool ValidateSolution(long actual, long expected){
              return new JavaScriptSerializer().Serialize(actual) == new JavaScriptSerializer().Serialize(expected);
          }
  
          public string driver(List<int> a, int n, long expected){
              try{
                PLACEHOLDER_CLS_NAME solution_cls = new PLACEHOLDER_CLS_NAME();
                long pred_result = solution_cls.PLACEHOLDER_FN_NAME(a, n); 
                if (ValidateSolution(
                      pred_result,
                      expected)){
                  return "PASSED";
                }
                return "FAILED";
              } 
              catch (Exception exception_obj)
              {
                return exception_obj.GetType().FullName;
              }
          }
          static void Main(string[] args) {
              TestRunner runner = new TestRunner();
              String result;
              result = runner.driver(
                  new List<int>{4, 16, 29, 30, 38, 83}, 5, 
                  918
              );
              Console.WriteLine(string.Format(
                  "TEST-0...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{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
              );
              Console.WriteLine(string.Format(
                  "TEST-1...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{0, 1}, 1, 
                  0
              );
              Console.WriteLine(string.Format(
                  "TEST-2...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{7, 12, 78, 8}, 3, 
                  90
              );
              Console.WriteLine(string.Format(
                  "TEST-3...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{-78, -48, -48, -26, 8, 34}, 4, 
                  -1334
              );
              Console.WriteLine(string.Format(
                  "TEST-4...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{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
              );
              Console.WriteLine(string.Format(
                  "TEST-5...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{2, 3, 5, 7, 25, 30, 31, 38, 42, 45, 52, 53, 56, 59, 60, 71, 74, 76, 80, 90, 91, 98}, 13, 
                  3190079
              );
              Console.WriteLine(string.Format(
                  "TEST-6...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{0, 0, 0, 0, 0, 0, 1, 1, 1}, 8, 
                  2
              );
              Console.WriteLine(string.Format(
                  "TEST-7...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{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
              );
              Console.WriteLine(string.Format(
                  "TEST-8...{0}",
                  result)
              );
          }
      }
  }
  
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;
  }